UNPKG

1.52 kBJavaScriptView Raw
1'use strict';
2var bind = require('../internals/function-bind-context');
3var uncurryThis = require('../internals/function-uncurry-this');
4var IndexedObject = require('../internals/indexed-object');
5var toObject = require('../internals/to-object');
6var toPropertyKey = require('../internals/to-property-key');
7var lengthOfArrayLike = require('../internals/length-of-array-like');
8var objectCreate = require('../internals/object-create');
9var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
10
11var $Array = Array;
12var push = uncurryThis([].push);
13
14module.exports = function ($this, callbackfn, that, specificConstructor) {
15 var O = toObject($this);
16 var self = IndexedObject(O);
17 var boundFunction = bind(callbackfn, that);
18 var target = objectCreate(null);
19 var length = lengthOfArrayLike(self);
20 var index = 0;
21 var Constructor, key, value;
22 for (;length > index; index++) {
23 value = self[index];
24 key = toPropertyKey(boundFunction(value, index, O));
25 // in some IE versions, `hasOwnProperty` returns incorrect result on integer keys
26 // but since it's a `null` prototype object, we can safely use `in`
27 if (key in target) push(target[key], value);
28 else target[key] = [value];
29 }
30 // TODO: Remove this block from `core-js@4`
31 if (specificConstructor) {
32 Constructor = specificConstructor(O);
33 if (Constructor !== $Array) {
34 for (key in target) target[key] = arrayFromConstructorAndList(Constructor, target[key]);
35 }
36 } return target;
37};