Re:TC39: Add Object.groupBy and Map.groupBy
by tibbar on Tuesday December 19, 2023 @04:44PM
(#38702094)
I think `out` should be typed as a map to an array in this case; each iteration should be appending to the corresponding array instead of overwriting the entire entry.
Re:TC39: Add Object.groupBy and Map.groupBy
by moritzwarhier on Tuesday December 19, 2023 @04:50PM
(#38702170)
Oh yes, I agree.
I remember me running into the problem of internal dependencies when extracting parts of it into a non-ESM/non-build project some years ago...
Like, the internal consistency of the library probably benefits, and with tree-shaking it works reasonably well but it is still a poster example of DRY vs KISS...
It has its benefits, but its API surface can be annoying, too. When I encounter it, I often have to think for a second and look at the docs, e.g. some cryptic xor or map function with three parameters, one of which being an optional config object.
OTOH, it can be great to have a well-tested implementation at hand for all kinds of higher-order functions, like throttle, debounce etc
Re:TC39: Add Object.groupBy and Map.groupBy
by explaininjs on Tuesday December 19, 2023 @05:34PM
(#38702834)
Aaannd… now you have a prototype pollution vulnerability :)
Object.from(null), always.
This is probably missing checking for a bunch of corner cases, but this is the general idea:
I literally wrote something very like this yesterday (after checking & finding it only got added to Node 21, and deciding not to pull in a dependency).Edit: had keyBy impl in here, fixed! Thanks commenters!