Ignores non-present values

This commit is contained in:
Mohammed Nabeel 2020-07-15 18:26:03 +03:00
parent 4250c06303
commit 1aa228d42c
2 changed files with 4 additions and 2 deletions

View File

@ -7,8 +7,10 @@ const removeFromArray = function(...args) {
// Remove all the remaining elements from the array // Remove all the remaining elements from the array
for (let i = 1; i < args.length; i++) { for (let i = 1; i < args.length; i++) {
pos = myArray.indexOf(args[i]); pos = myArray.indexOf(args[i]);
if (pos >= 0) { //Is it a valid argument
myArray.splice(pos, 1); myArray.splice(pos, 1);
} }
}
return myArray; return myArray;

View File

@ -7,7 +7,7 @@ describe('removeFromArray', function() {
it('removes multiple values', function() { it('removes multiple values', function() {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
}); });
xit('ignores non present values', function() { it('ignores non present values', function() {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
}); });
xit('ignores non present values, but still works', function() { xit('ignores non present values, but still works', function() {