diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index 6d882c0..0405b22 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -7,7 +7,7 @@ const removeFromArray = function(...args) { // Remove all the remaining elements from the array for (let i = 1; i < args.length; i++) { pos = myArray.indexOf(args[i]); - if (pos >= 0) { //Is it a valid argument + if (pos >= 0 && myArray[pos] === args[i]) { //Is it a valid argument myArray.splice(pos, 1); } } diff --git a/removeFromArray/removeFromArray.spec.js b/removeFromArray/removeFromArray.spec.js index 4e319b9..b280f00 100644 --- a/removeFromArray/removeFromArray.spec.js +++ b/removeFromArray/removeFromArray.spec.js @@ -13,13 +13,13 @@ describe('removeFromArray', function() { it('ignores non present values, but still works', function() { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - xit('can remove all values', function() { + it('can remove all values', function() { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - xit('works with strings', function() { + it('works with strings', function() { expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); }); - xit('only removes same type', function() { + it('only removes same type', function() { expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); }); }); \ No newline at end of file