groupLength.js (645B)
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-map.groupby 6 description: Map.groupBy populates Map with correct keys and values 7 info: | 8 Map.groupBy ( items, callbackfn ) 9 10 ... 11 includes: [compareArray.js] 12 features: [array-grouping, Map, Symbol.iterator] 13 ---*/ 14 15 const arr = ['hello', 'test', 'world']; 16 17 const map = Map.groupBy(arr, function (i) { return i.length; }); 18 19 assert.compareArray(Array.from(map.keys()), [5, 4]); 20 assert.compareArray(map.get(5), ['hello', 'world']); 21 assert.compareArray(map.get(4), ['test']); 22 23 reportCompare(0, 0);