Ensure _.ary treats negative n values as 0.

This commit is contained in:
jdalton
2015-01-25 12:12:41 -08:00
parent ed61d0c591
commit 47a5b227cc
2 changed files with 11 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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']);