Comparison error

I was expecting [1, 1] but it turns out that I messed with filter method. Why the program returns the same array?

function destroyer(arr) {
 let len = arguments.length;
	let args= [...arguments[0]];
	//console.log(args); TESTED OK

 function find() {
   for (let i = 1; i < len; i++) {
		console.log(`in filter loop, ${args[i]}, ${item}`); 
		return item!==args[i]; //line 12, why it's always true? 
	return `from find [${args}]`;

return find()
let x= destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Challenge: Seek and Destroy

Link to the challenge:

filter doesn’t change the array on which it is used, it returns a new array, but you are not capturing that new array, you are not using it


So, a few suggestions. First, when you use the filter function, you no longer need the for Loop. They do much the same. In essence, what you are doing is taking each member of The Argus array and checking to see that it is in the args array. Is that your intent?

Also, when you convert arguments zero into the args variable, what you are doing is setting the array into the Argus variable which may be what you want. However you never deal with any additional arguments.

A way to handle this maybe in the perimeter arguments, or the way that you handle them. I assume you want args to be the items to remove. In that case, simply reference that in the parameter:

function destroyer(arr, ...args){...}

That says “make the first parameter a variable named arr, and everything else the variables args.”

1 Like

In addition to what is mentioned above, you are supposed to return an array, but do actually return a string.

1 Like

thankU…how come I forgot it!!!

that’s nice, thankU :clap:

Thanks a ton to draw my attention to this… what I found, when u wanna log array under backtick, it spreads the elements within, so no more array. :+1: