Debian Codegraph @

js/src/tests/test262/built-ins/Object/groupBy/evenOdd.js

raw
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: Object.groupBy populates object with correct keys and values
7 info: |
8 Object.groupBy ( items, callbackfn )
9 ...
10 includes: [compareArray.js]
11 features: [array-grouping]
12 ---*/
13
14 const array = [1, 2, 3];
15
16 const obj = Object.groupBy(array, function (i) {
17 return i % 2 === 0 ? 'even' : 'odd';
18 });
19
20 assert.compareArray(Object.keys(obj), ['odd', 'even']);
21 assert.compareArray(obj['even'], [2]);
22 assert.compareArray(obj['odd'], [1, 3]);
23
24 reportCompare(0, 0);