mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Fix coercing arity in baseCurry.
This commit is contained in:
@@ -1624,7 +1624,7 @@
|
|||||||
*/
|
*/
|
||||||
function baseCurry(func, bitmask, arity) {
|
function baseCurry(func, bitmask, arity) {
|
||||||
if (typeof arity != 'number') {
|
if (typeof arity != 'number') {
|
||||||
arity = +arity || (func ? func.length : 0);
|
arity = arity == null ? (func ? func.length : 0) : (+arity || 0);
|
||||||
}
|
}
|
||||||
return createWrapper([func, bitmask, arity]);
|
return createWrapper([func, bitmask, arity]);
|
||||||
}
|
}
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -2229,7 +2229,7 @@
|
|||||||
deepEqual(curried(1, 2, 3, 4), expected);
|
deepEqual(curried(1, 2, 3, 4), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should allow specifying `arity`', 3, function(){
|
test('should allow specifying `arity`', 3, function() {
|
||||||
var curried = _.curry(fn, 3),
|
var curried = _.curry(fn, 3),
|
||||||
expected = [1, 2, 3];
|
expected = [1, 2, 3];
|
||||||
|
|
||||||
@@ -2238,6 +2238,21 @@
|
|||||||
deepEqual(curried(1, 2, 3), expected);
|
deepEqual(curried(1, 2, 3), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should coerce `arity` to a number', 2, function() {
|
||||||
|
var values = ['0', 'xyz'],
|
||||||
|
expected = _.map(values, _.constant([]));
|
||||||
|
|
||||||
|
var actual = _.map(values, function(arity) {
|
||||||
|
var curried = _.curry(fn, arity);
|
||||||
|
return curried();
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
|
||||||
|
curried = _.curry(fn, '2');
|
||||||
|
deepEqual(curried(1)(2), [1, 2]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should work with partialed methods', 2, function() {
|
test('should work with partialed methods', 2, function() {
|
||||||
var curried = _.curry(fn),
|
var curried = _.curry(fn),
|
||||||
expected = [1, 2, 3, 4];
|
expected = [1, 2, 3, 4];
|
||||||
|
|||||||
Reference in New Issue
Block a user