You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

17 lines
339 B

export function groupBy(groupFn, list){
if (arguments.length === 1) return _list => groupBy(groupFn, _list)
const result = {}
for (let i = 0; i < list.length; i++){
const item = list[ i ]
const key = groupFn(item)
if (!result[ key ]){
result[ key ] = []
}
result[ key ].push(item)
}
return result
}