I'm solving a coding exercise and ran into a interesting problem. I am trying to filter an array by arguments (I don't know in advance how many arguments there will be). So the first argument of my function is always an array, followed by a random number of integers I need to filter out.
I figured I'd solve this by nesting a for loop inside my filter function, but so far it only filters by the first argument and ignores the second one. Is this due to using return false/true? If so, what could I use instead?
function destroyer(arr) {
var output = [];
for (var y = 1; y < arguments.length; y++) {
output.push(arguments[y]);
}
function destroy(value) {
for (var x = 0; x < output.length; x++) {
if (value === output[x]) {
return false;
} else {
return true;
}
}
}
return arr.filter(destroy);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Thanks for the help