mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Make _.drop, _.dropRight, _.take, _.takeRight coerce n of undefined to 0.
This commit is contained in:
@@ -4654,7 +4654,7 @@
|
||||
if (!(array && array.length)) {
|
||||
return [];
|
||||
}
|
||||
n = (guard || n == null) ? 1 : n;
|
||||
n = (guard || n === undefined) ? 1 : n;
|
||||
return baseSlice(array, n < 0 ? 0 : n);
|
||||
}
|
||||
|
||||
@@ -4687,7 +4687,7 @@
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
n = (guard || n == null) ? 1 : toInteger(n);
|
||||
n = (guard || n === undefined) ? 1 : toInteger(n);
|
||||
n = length - n;
|
||||
return baseSlice(array, 0, n < 0 ? 0 : n);
|
||||
}
|
||||
@@ -5517,7 +5517,7 @@
|
||||
if (!(array && array.length)) {
|
||||
return [];
|
||||
}
|
||||
n = (guard || n == null) ? 1 : n;
|
||||
n = (guard || n === undefined) ? 1 : n;
|
||||
return baseSlice(array, 0, n < 0 ? 0 : n);
|
||||
}
|
||||
|
||||
@@ -5550,7 +5550,7 @@
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
n = (guard || n == null) ? 1 : toInteger(n);
|
||||
n = (guard || n === undefined) ? 1 : toInteger(n);
|
||||
n = length - n;
|
||||
return baseSlice(array, n < 0 ? 0 : n);
|
||||
}
|
||||
|
||||
16
test/test.js
16
test/test.js
@@ -3645,11 +3645,11 @@
|
||||
assert.deepEqual(_.drop(array, 2), [3]);
|
||||
});
|
||||
|
||||
QUnit.test('should treat falsey `n` values, except nullish, as `0`', function(assert) {
|
||||
QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = _.map(falsey, function(value) {
|
||||
return value == null ? [2, 3] : array;
|
||||
return value === undefined ? [2, 3] : array;
|
||||
});
|
||||
|
||||
var actual = _.map(falsey, function(n) {
|
||||
@@ -3733,11 +3733,11 @@
|
||||
assert.deepEqual(_.dropRight(array, 2), [1]);
|
||||
});
|
||||
|
||||
QUnit.test('should treat falsey `n` values, except nullish, as `0`', function(assert) {
|
||||
QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = _.map(falsey, function(value) {
|
||||
return value == null ? [1, 2] : array;
|
||||
return value === undefined ? [1, 2] : array;
|
||||
});
|
||||
|
||||
var actual = _.map(falsey, function(n) {
|
||||
@@ -4746,11 +4746,11 @@
|
||||
assert.deepEqual(_.take(array, 2), [1, 2]);
|
||||
});
|
||||
|
||||
QUnit.test('should treat falsey `n` values, except nullish, as `0`', function(assert) {
|
||||
QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = _.map(falsey, function(value) {
|
||||
return value == null ? [1] : [];
|
||||
return value === undefined ? [1] : [];
|
||||
});
|
||||
|
||||
var actual = _.map(falsey, function(n) {
|
||||
@@ -4828,11 +4828,11 @@
|
||||
assert.deepEqual(_.takeRight(array, 2), [2, 3]);
|
||||
});
|
||||
|
||||
QUnit.test('should treat falsey `n` values, except nullish, as `0`', function(assert) {
|
||||
QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = _.map(falsey, function(value) {
|
||||
return value == null ? [3] : [];
|
||||
return value === undefined ? [3] : [];
|
||||
});
|
||||
|
||||
var actual = _.map(falsey, function(n) {
|
||||
|
||||
Reference in New Issue
Block a user