Object.groupBy()
groups elements
the interface
groupBy
is a static function, on Object
the parameters MUST BE an iterable (array, object, ...) AND a function
the returns value is an object
how it works?
WHEN the callback returns a string THEN the object is grouped by that string
use case: group products sold by country
WHEN the callback returns undefined
THEN this returns an object {undefined: <all items>}
the return value of callback is converted into a string
the returned items are the SAME as the original ones (no copies)
Links
The repository where the proposal was worked on.
The "ECMAScript Language Specification", the JavaScript specification text describing this function how an engine must implement it.
The Mozilla Developer Network docs.
Required Knowledge
- `array.toReversed()` (Array API)
Related Katas
Global Object API
Object API
Object()
(as introduced in ES1)Object.is()
Object.fromEntries()
Object.fromEntries()
in depthObject.groupBy()
Object literal
Difficulty Level
BEGINNER
First Published
24 October 2024
Stats
8 tests to solve