diff --git a/src/helpers.js b/src/helpers.js index 80602e8..9bc512e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -573,6 +573,9 @@ export function splice(array, startIndex, nb, ...elements) { if (nb === undefined) { nb = array.length - startIndex; } + else if (nb === null || Number.isNaN(Number.parseInt(nb))) { + nb = 0; + } nb = Math.max(0, nb); // Solving startIndex diff --git a/test/suites/helpers.js b/test/suites/helpers.js index 6196f5d..043ee0b 100644 --- a/test/suites/helpers.js +++ b/test/suites/helpers.js @@ -231,6 +231,16 @@ describe('Helpers', function() { assert.deepEqual(splice(array, 2), [0, 1]); assert.deepEqual(splice(array, -2), [0, 1, 2]); + + assert.deepEqual(splice(array, 2, null), [0, 1, 2, 3, 4]); + }); + + it('should delete no values when supplying an argument which is not parseable as number', function () { + const array = [0, 1, 2, 3, 4]; + + assert.deepEqual(splice(array, 2, "a"), [0, 1, 2, 3, 4]); + + assert.deepEqual(splice(array, 2, {}), [0, 1, 2, 3, 4]); }); }); });