groupLength.js (751B)
1 // Copyright (c) 2023 Ecma International. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-object.groupby 6 description: Callback can return numbers that are converted to property keys 7 info: | 8 Object.groupBy ( items, callbackfn ) 9 10 ... 11 GroupBy ( items, callbackfn, coercion ) 12 13 6. Repeat, 14 c. If next is false, then 15 i. Return groups. 16 ... 17 includes: [compareArray.js] 18 features: [array-grouping] 19 ---*/ 20 21 const arr = ['hello', 'test', 'world']; 22 23 const obj = Object.groupBy(arr, function (i) { return i.length; }); 24 25 assert.compareArray(Object.keys(obj), ['4', '5']); 26 assert.compareArray(obj['5'], ['hello', 'world']); 27 assert.compareArray(obj['4'], ['test']); 28 29 reportCompare(0, 0);