Hi,
I already found a different route to solve the Seek & Destroy challenge, but still wondering why my first attempt didn’t work.
I first created conStr as the filter string, which works fine. But when I use that variable in the actual filter callback function (hasToGo) than it is disregarded somehow. Whereas when I manually type the exact same contents of conStr, it works just fine.
Wonder where this goes wrong for future challenges.
Thanks,
Erlend
function destroyer(arr) {
// Remove all the values
var args = Array.from(arguments);
var conStr = "";
for (var i = 1; i < args.length; i++) {
if (i == 1) {
conStr = "value != " + args[i];
} else {
conStr += " && value != " + args[i];
}
}
console.log(conStr);
function hasToGo(value) {
// return value != 2 && value != 3;
return conStr ;
}
var filtered = args[0].filter(hasToGo);
console.log(filtered);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);