| export function countBy(fn, list){ | |
| if (arguments.length === 1){ | |
| return _list => countBy(fn, _list) | |
| } | |
| const willReturn = {} | |
| list.forEach(item => { | |
| const key = fn(item) | |
| if (!willReturn[ key ]){ | |
| willReturn[ key ] = 1 | |
| } else { | |
| willReturn[ key ]++ | |
| } | |
| }) | |
| return willReturn | |
| } |