@@ -3,24 +3,30 @@ var has = require('../internals/has');
3
3
var IndexedObject = require ( '../internals/indexed-object' ) ;
4
4
var toObject = require ( '../internals/to-object' ) ;
5
5
var toLength = require ( '../internals/to-length' ) ;
6
- var toPrimitive = require ( '../internals/to-primitive ' ) ;
6
+ var toPropertyKey = require ( '../internals/to-property-key ' ) ;
7
7
var objectCreate = require ( '../internals/object-create' ) ;
8
+ var arrayFromConstructorAndList = require ( '../internals/array-from-constructor-and-list' ) ;
8
9
9
10
var push = [ ] . push ;
10
11
11
- module . exports = function ( $this , callbackfn , that , specificCreate ) {
12
+ module . exports = function ( $this , callbackfn , that , specificConstructor ) {
12
13
var O = toObject ( $this ) ;
13
14
var self = IndexedObject ( O ) ;
14
15
var boundFunction = bind ( callbackfn , that , 3 ) ;
15
16
var target = objectCreate ( null ) ;
16
17
var length = toLength ( self . length ) ;
17
18
var index = 0 ;
18
- var value , result , array ;
19
+ var Constructor , key , value ;
19
20
for ( ; length > index ; index ++ ) {
20
21
value = self [ index ] ;
21
- result = toPrimitive ( boundFunction ( value , index , O ) , 'string' ) ;
22
- if ( has ( target , result ) ) array = target [ result ] ;
23
- else target [ result ] = array = specificCreate ? specificCreate ( $this , 0 ) : [ ] ;
24
- push . call ( array , value ) ;
22
+ key = toPropertyKey ( boundFunction ( value , index , O ) ) ;
23
+ if ( has ( target , key ) ) push . call ( target [ key ] , value ) ;
24
+ else target [ key ] = [ value ] ;
25
+ }
26
+ if ( specificConstructor ) {
27
+ Constructor = specificConstructor ( O ) ;
28
+ if ( Constructor !== Array ) {
29
+ for ( key in target ) target [ key ] = arrayFromConstructorAndList ( Constructor , target [ key ] ) ;
30
+ }
25
31
} return target ;
26
32
} ;
0 commit comments