Search terms: proposal-array-grouping array groupBy ernest
lib Update Request
With advancement into stage 3, it's time for JS engines, transpilers and toolings to start implementing support for new features and provide feedback for the proposal's advancement into stage 4.
Configuration Check
This is so new that it needs to go into ESNext target.
Missing / Incorrect Definition
Missing Array.prototype.groupBy and Array.prototype.groupByToMap.
Sample Code
constarray=[1,2,3,4,5];// groupBy groups items by arbitrary key.// In this case, we're grouping by even/odd keysarray.groupBy((num,index,array)=>{returnnum%2===0 ? 'even': 'odd';});// => { odd: [1, 3, 5], even: [2, 4] }// groupByToMap returns items in a Map, and is useful for grouping using// an object key.constodd={odd: true};consteven={even: true};array.groupByToMap((num,index,array)=>{returnnum%2===0 ? even: odd;});// => Map { {odd: true}: [1, 3, 5], {even: true}: [2, 4] }
I asked, and we generally think this might be ok to have the more accurate typing accurately reflecting the source object. Will need a bit of testing out when there's a PR
Yeah, I think we could think of this as closer to fromEntries; however, fromEntries doesn't try to preserve keys at all (and I don't think it even (cleanly) could).
The proposal for
Array.prototype.groupByandArray.prototype.groupByToMapreached stage 3 recently (although the proposal page has not been updated from stage 2).Search terms: proposal-array-grouping array groupBy ernest
lib Update Request
With advancement into stage 3, it's time for JS engines, transpilers and toolings to start implementing support for new features and provide feedback for the proposal's advancement into stage 4.
Configuration Check
This is so new that it needs to go into
ESNexttarget.Missing / Incorrect Definition
Missing
Array.prototype.groupByandArray.prototype.groupByToMap.Sample Code
Sample code from https://github.com/es-shims/Array.prototype.groupBy
Documentation Link
Proposal: proposal-array-grouping
Listing of proposal-array-grouping as stage 3
Shim implementation that can the code can be tested against: es-shims/Array.prototype.groupBy
The text was updated successfully, but these errors were encountered: