mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Ensure _.ary treats negative n values as 0.
This commit is contained in:
@@ -6683,7 +6683,7 @@
|
||||
if (guard && isIterateeCall(func, n, guard)) {
|
||||
n = null;
|
||||
}
|
||||
n = n == null ? func.length : (+n || 0);
|
||||
n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
|
||||
return createWrapper(func, ARY_FLAG, null, null, null, null, n);
|
||||
}
|
||||
|
||||
|
||||
10
test/test.js
10
test/test.js
@@ -896,6 +896,16 @@
|
||||
deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
test('should treat a negative `n` as `0`', 1, function() {
|
||||
var capped = _.ary(fn, -1);
|
||||
|
||||
try {
|
||||
var actual = capped('a');
|
||||
} catch(e) {}
|
||||
|
||||
deepEqual(actual, []);
|
||||
});
|
||||
|
||||
test('should work when provided less than the capped numer of arguments', 1, function() {
|
||||
var capped = _.ary(fn, 3);
|
||||
deepEqual(capped('a'), ['a']);
|
||||
|
||||
Reference in New Issue
Block a user