MCPcopy
hub / github.com/prettier/prettier / groupBy

Function groupBy

src/cli/utilities.js:17–31  ·  view source on GitHub ↗

* @template Obj * @template Key * @param {Array } array * @param {(value: Obj) => Key} iteratee * @returns {{[p in Key]: T}}

(array, iteratee)

Source from the content-addressed store, hash-verified

15 * @returns {{[p in Key]: T}}
16 */
17function 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

Callers 2

createUsageFunction · 0.90
object.jsFile · 0.50

Calls 1

createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…