AniUI Academy
Live noweasy+150 XPLive Challenge

Build your own groupBy

Almost every list you render is grouped by something: orders by status, students by year, commits by author.

Implement groupBy(items, keyFn). It takes an array and a function that returns the grouping key for an item, returning an object mapping keys to arrays.

What it has to do

  • Preserve the original order of items inside each group.
  • Handle an empty array by returning an empty object.
  • Accept keys that are numbers as well as strings.
  • Do not mutate the input array.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.