1 | 'use strict';
|
2 | var bind = require('../internals/function-bind-context');
|
3 | var uncurryThis = require('../internals/function-uncurry-this');
|
4 | var IndexedObject = require('../internals/indexed-object');
|
5 | var toObject = require('../internals/to-object');
|
6 | var toPropertyKey = require('../internals/to-property-key');
|
7 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
8 | var objectCreate = require('../internals/object-create');
|
9 | var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
|
10 |
|
11 | var $Array = Array;
|
12 | var push = uncurryThis([].push);
|
13 |
|
14 | module.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 |
|
26 |
|
27 | if (key in target) push(target[key], value);
|
28 | else target[key] = [value];
|
29 | }
|
30 |
|
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 | };
|