Iterate over an array and create a new sorted object.
I'm completely brain farting.
I have data coming in like
and I need to sort them to create an object with this shape:
And I'm struggling to think of an elegant way to do this.
Any suggestions?
6 Replies
Array.prototype.group() - JavaScript | MDN
The group() method groups the elements of the calling array according to the string values returned by a provided testing function.
The returned object has separate properties for each group, containing arrays with the elements in the group.
Basically does what you want
yeah but that's still experimental
Oh mb, although it is easy to find an implementation of this one using reduce which could be considered elegant
I came up with this
Looks good 👍