forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.map.group-by.js
27 lines (21 loc) · 952 Bytes
/
es.map.group-by.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createIterable } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/es/map';
QUnit.test('Map.groupBy', assert => {
const { groupBy } = Map;
assert.isFunction(groupBy);
assert.arity(groupBy, 2);
assert.name(groupBy, 'groupBy');
assert.true(groupBy([], it => it) instanceof Map);
assert.deepEqual(from(groupBy([], it => it)), []);
assert.deepEqual(from(groupBy([1, 2], it => it ** 2)), [[1, [1]], [4, [2]]]);
assert.deepEqual(from(groupBy([1, 2, 1], it => it ** 2)), [[1, [1, 1]], [4, [2]]]);
assert.deepEqual(from(groupBy(createIterable([1, 2]), it => it ** 2)), [[1, [1]], [4, [2]]]);
assert.deepEqual(from(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string');
const element = {};
groupBy([element], function (it, i) {
assert.same(arguments.length, 2);
assert.same(it, element);
assert.same(i, 0);
});
});