Should coerce float start and end params of _.slice to integers.

This commit is contained in:
jdalton
2015-01-28 23:33:30 -08:00
parent db3b6a1252
commit 2ee0634db3
2 changed files with 4 additions and 3 deletions

View File

@@ -2661,7 +2661,8 @@
if (end < 0) {
end += length;
}
length = start > end ? 0 : (end - start);
length = start > end ? 0 : (end - start) >>> 0;
start >>>= 0;
var result = Array(length);
while (++index < length) {

View File

@@ -11690,8 +11690,8 @@
});
test('should coerce `start` and `end` to finite numbers', 1, function() {
var actual = [_.slice(array, '0', 1), _.slice(array, 0, '1'), _.slice(array, '1'), _.slice(array, NaN, 1), _.slice(array, 1, NaN)];
deepEqual(actual, [[1], [1], [2, 3], [1], []]);
var actual = [_.slice(array, 0.1, 1.1), _.slice(array, '0', 1), _.slice(array, 0, '1'), _.slice(array, '1'), _.slice(array, NaN, 1), _.slice(array, 1, NaN)];
deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
});
test('should work as an iteratee for `_.map`', 2, function() {