Skip to main content
Module

x/rambda/source/indexBy.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {path} from './path'
function indexByPath(pathInput, list) { const toReturn = {} for (let i = 0; i < list.length; i++) { const item = list[i] toReturn[path(pathInput, item)] = item }
return toReturn}
export function indexBy(condition, list) { if (arguments.length === 1) { return _list => indexBy(condition, _list) }
if (typeof condition === 'string') { return indexByPath(condition, list) }
const toReturn = {} for (let i = 0; i < list.length; i++) { const item = list[i] toReturn[condition(item)] = item }
return toReturn}