deno.land / x / rambda@v9.1.1 / src / collectBy.js
12345678910111213141516171819202122232425262728import { reduce } from './reduce.js'
export function collectBy(fn, list){ if (arguments.length === 1){ return _list => collectBy(fn, _list) }
const group = reduce( (o, x) => { const tag = fn(x) if (o[ tag ] === undefined){ o[ tag ] = [] } o[ tag ].push(x)
return o }, {}, list ) const newList = [] for (const tag in group){ newList.push(group[ tag ]) }
return newList}
Version Info