Skip to content

Commit

Permalink
fixed bug w/ map-keys on arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Aug 21, 2016
1 parent 77c225d commit 2261999
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ function extendChainPrototype (hideWarnings) {

return this
},
enumerable: false,
configurable: envIs('test') // hack for tests
enumerable: false
})
})
}
10 changes: 6 additions & 4 deletions map-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ function mapKeys (obj, callback, thisArg) {
throw new TypeError(callback + ' must be a function')
}
var objIsArray = Array.isArray(obj)
var mapped = objIsArray ? [] : {}
if (objIsArray) {
forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach)
obj.forEach(eachCallback)
} else {
forEach(obj, eachCallback)
}
var mapped = objIsArray ? [] : {}
forEach(obj, function (val, key, obj) {
function eachCallback (val, key, obj) {
var newKey = callback.call(thisArg, key, val, obj)
mapped[newKey] = val
})
}
return mapped
}
/**
Expand Down
6 changes: 5 additions & 1 deletion test/test-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ describe('chain', function () {
.map(mapCb)
.mapKeys(mapKeysCb)
.reduce(reduceCb)
.keys()
.map(mapCb)
.mapKeys(mapKeysCb)
.reduce(reduceCb)
.toJSON()
expect(output).to.deep.equal({ x: 1, y: 1 })
expect(output).to.deep.equal(['x', 'y'])
done()
})
it('should have all methods', function (done) {
Expand Down

0 comments on commit 2261999

Please sign in to comment.