source: imaps-frontend/node_modules/core-js/modules/es.map.group-by.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[79a0317]1'use strict';
2var $ = require('../internals/export');
3var uncurryThis = require('../internals/function-uncurry-this');
4var aCallable = require('../internals/a-callable');
5var requireObjectCoercible = require('../internals/require-object-coercible');
6var iterate = require('../internals/iterate');
7var MapHelpers = require('../internals/map-helpers');
8var IS_PURE = require('../internals/is-pure');
9var fails = require('../internals/fails');
10
11var Map = MapHelpers.Map;
12var has = MapHelpers.has;
13var get = MapHelpers.get;
14var set = MapHelpers.set;
15var push = uncurryThis([].push);
16
17var DOES_NOT_WORK_WITH_PRIMITIVES = IS_PURE || fails(function () {
18 return Map.groupBy('ab', function (it) {
19 return it;
20 }).get('a').length !== 1;
21});
22
23// `Map.groupBy` method
24// https://tc39.es/ecma262/#sec-map.groupby
25$({ target: 'Map', stat: true, forced: IS_PURE || DOES_NOT_WORK_WITH_PRIMITIVES }, {
26 groupBy: function groupBy(items, callbackfn) {
27 requireObjectCoercible(items);
28 aCallable(callbackfn);
29 var map = new Map();
30 var k = 0;
31 iterate(items, function (value) {
32 var key = callbackfn(value, k++);
33 if (!has(map, key)) set(map, key, [value]);
34 else push(get(map, key), value);
35 });
36 return map;
37 }
38});
Note: See TracBrowser for help on using the repository browser.