A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-151.js
1constusers=[{role:'a'},{role:'b'},{role:'a'}];
2constg=Object.groupBy(users,u=>u.role);
3console.log(g.a.length,g.b.length);
Quirks
Answer & explanation
Console output
2 1
Why
Object.groupBy partitions a collection into an object keyed by the callback’s return value, with each key mapping to an array of the items that produced it. Two users have role "a" and one has "b", so g.a holds two entries and g.b holds one. It is a concise replacement for manual reduce-based grouping.