All exercises

groupBy

ChallengeTypeScript

Runs entirely in your browser — your code never leaves your machine.

Problem

Implement groupBy(items, keyFn): walk the items and group them into an object whose keys are keyFn(item) and whose values are arrays of the items that produced that key, in their original order. groupBy([1,2,3,4], n => n % 2 === 0 ? "even" : "odd") → { odd: [1, 3], even: [2, 4] }

Related cheat sheet
Your code
Press Run tests to check your solution.