| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1 7 7 7 7 1 6 7 39 39 7 | function indexBy(xs, iteratee, thisArg) {
let i = 0;
let indices = {};
let fn;
if (typeof iteratee === 'string') {
fn = x => x[iteratee];
} else {
fn = thisArg ? iteratee.bind(thisArg) : iteratee;
}
for (let x of xs) {
indices[fn(x, i, xs)] = x;
i += 1;
}
return indices;
}
export default indexBy;
|