blob: b28522b1cb2516a47b1710a638709477726ad9e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// Copyright (c) 2023 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.groupby
description: Object.groupBy populates object with correct keys and values
info: |
Object.groupBy ( items, callbackfn )
...
includes: [compareArray.js]
features: [array-grouping]
---*/
const array = [1, 2, 3];
const obj = Object.groupBy(array, function (i) {
return i % 2 === 0 ? 'even' : 'odd';
});
assert.compareArray(Object.keys(obj), ['odd', 'even']);
assert.compareArray(obj['even'], [2]);
assert.compareArray(obj['odd'], [1, 3]);
reportCompare(0, 0);
|