Skip to content

Commit 2261999

Browse files
committed
fixed bug w/ map-keys on arrays
1 parent 77c225d commit 2261999

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

chain.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ function extendChainPrototype (hideWarnings) {
6262

6363
return this
6464
},
65-
enumerable: false,
66-
configurable: envIs('test') // hack for tests
65+
enumerable: false
6766
})
6867
})
6968
}

map-keys.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ function mapKeys (obj, callback, thisArg) {
1818
throw new TypeError(callback + ' must be a function')
1919
}
2020
var objIsArray = Array.isArray(obj)
21+
var mapped = objIsArray ? [] : {}
2122
if (objIsArray) {
22-
forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach)
23+
obj.forEach(eachCallback)
24+
} else {
25+
forEach(obj, eachCallback)
2326
}
24-
var mapped = objIsArray ? [] : {}
25-
forEach(obj, function (val, key, obj) {
27+
function eachCallback (val, key, obj) {
2628
var newKey = callback.call(thisArg, key, val, obj)
2729
mapped[newKey] = val
28-
})
30+
}
2931
return mapped
3032
}
3133
/**

test/test-chain.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ describe('chain', function () {
2323
.map(mapCb)
2424
.mapKeys(mapKeysCb)
2525
.reduce(reduceCb)
26+
.keys()
27+
.map(mapCb)
28+
.mapKeys(mapKeysCb)
29+
.reduce(reduceCb)
2630
.toJSON()
27-
expect(output).to.deep.equal({ x: 1, y: 1 })
31+
expect(output).to.deep.equal(['x', 'y'])
2832
done()
2933
})
3034
it('should have all methods', function (done) {

0 commit comments

Comments
 (0)