ts-prime
Version:
A utility library for JavaScript and Typescript.
19 lines (18 loc) • 554 B
JavaScript
import { purry } from './purry';
export function indexBy() {
return purry(_indexBy(false), arguments);
}
var _indexBy = function (indexed) { return function (array, fn) {
return array.reduce(function (ret, item, index) {
var value = indexed ? fn(item, index, array) : fn(item);
var key = String(value);
ret[key] = item;
return ret;
}, {});
}; };
(function (indexBy) {
function indexed() {
return purry(_indexBy(true), arguments);
}
indexBy.indexed = indexed;
})(indexBy || (indexBy = {}));