evenOdd.js (637B)
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 includes: [compareArray.js] 11 features: [array-grouping, Map] 12 ---*/ 13 14 const array = [1, 2, 3]; 15 16 const map = Map.groupBy(array, function (i) { 17 return i % 2 === 0 ? 'even' : 'odd'; 18 }); 19 20 assert.compareArray(Array.from(map.keys()), ['odd', 'even']); 21 assert.compareArray(map.get('even'), [2]); 22 assert.compareArray(map.get('odd'), [1, 3]); 23 24 reportCompare(0, 0);