# Seek and Destroy-Basic Algorithm

Seek and Destroy-Basic Algorithm
0
#1

Hi guys,
so after more than a day of struggling, I finally managed to pass this challenge.
I was wondering tho , if I use this code:

if(arr.indexOf(agts[j])!==-1),

the code wont work, it will still initiate “splice” with starting point of “-1”, I dont understand why.

Thank you

V

Your code so far

function destroyer(arr) {

var agts= Array.prototype.slice.call(arguments,1);

for(var i=0;i<arr.length;i++){
for(var j=0;j<agts.length;j++){
if(arr.indexOf(agts[j])>-1)
arr.splice((arr.indexOf(agts[j])),1);
}
}
return arr;

}
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3);

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36.

Link to the challenge:

#2

If I change out the above line for

if(arr.indexOf(agts[j])!==-1)

your function passes all the tests.

function destroyer(arr) {
var agts= Array.prototype.slice.call(arguments,1);
for(var i=0; i < arr.length; i++){
for(var j=0; j< agts.length; j++){
if(arr.indexOf(agts[j])!==-1)
arr.splice((arr.indexOf(agts[j])),1);
}
}
return arr;
}
1 Like
#3

Oops, my bad, I must’ve made a mistake somewhere else, hence it didnt work.
Thank you for the reply.

#4

it took you a day?!?! this took me a week!

feel smart

1 Like
#5

Gee, thanks!! with what i’ve been feeling all week while reading MDN, your comment has just made my day

#6

i’ve been in FCC for three years, and 2 1/2 of those were spent on the intermediate javascript. i have thought many times about jumping off the manhattan bridge, don’t give up!

1 Like