* @template Obj * @template Key * @param {Array } array * @param {(value: Obj) => Key} iteratee * @returns {{[p in Key]: T}}
(array, iteratee)
| 15 | * @returns {{[p in Key]: T}} |
| 16 | */ |
| 17 | function groupBy(array, iteratee) { |
| 18 | const result = Object.create(null); |
| 19 | |
| 20 | for (const value of array) { |
| 21 | const key = iteratee(value); |
| 22 | |
| 23 | if (Array.isArray(result[key])) { |
| 24 | result[key].push(value); |
| 25 | } else { |
| 26 | result[key] = [value]; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return result; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @template Obj |
no test coverage detected
searching dependent graphs…