Could someone help me with this please, I dont understand why the filter line of code is not working, and why it is creating two arrays instead of one?
**Your code so far**
function destroyer(arr) {
//console.log('args:', arguments)
let args =[] //2,3
console.log('arr:', arr)
for (let i=1; i <arguments.length; i++){
args.push(arguments[i])
console.log('args:', args)
}
for (let j=0; j <args.length; j++){
let filtered = arr.filter(num => num !== args[j])
console.log(filtered)
}
return arr }
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38
Hi, sorry I have edited the code since so it is a bit different. Regardless of that I still dont understand why I would be checking if args contained num isnt it the other way round?
So I am trying to remove the elements that are the same as each argument in the args array, so if the element in arr is not equal to an element in args I want to maybe push that element in arr into a new array and return this?
Sounds like a filter to me: if the args includes a value that you find in newArr, that value shouldn’t be kept in newArr… Which goes back to that filter function. How can you, in code, say “not if arr includes this num?”