mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Ensure _.concat treats nullish values as empty arrays.
This commit is contained in:
@@ -5336,11 +5336,11 @@
|
|||||||
* // => [1]
|
* // => [1]
|
||||||
*/
|
*/
|
||||||
var concat = rest(function(array, values) {
|
var concat = rest(function(array, values) {
|
||||||
if (array == null) {
|
if (!isArray(array)) {
|
||||||
return [];
|
array = array == null ? [] : [Object(array)];
|
||||||
}
|
}
|
||||||
values = baseFlatten(values);
|
values = baseFlatten(values);
|
||||||
return arrayConcat(isArray(array) ? array : [Object(array)], values);
|
return arrayConcat(array, values);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
15
test/test.js
15
test/test.js
@@ -2842,6 +2842,21 @@
|
|||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should treat nullish `array` values as empty arrays', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var values = [null, undefined],
|
||||||
|
expected = lodashStable.map(values, lodashStable.constant([1, 2, [3]]));
|
||||||
|
|
||||||
|
var actual = lodashStable.map(values, function(value) {
|
||||||
|
try {
|
||||||
|
return _.concat(value, 1, [2], [[3]]);
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should treat sparse arrays as dense', function(assert) {
|
QUnit.test('should treat sparse arrays as dense', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user