Tell us what’s happening:
I tried to create a recursive function and just wanted anyone’s two cents on whether this is sub-optimal and if there’s a way to improve it then how can I do that?
Thanks!
Your code so far
function destroyer(arr) {
//if index of is found then splice
//otherwise move on
function destroy(args) {
if(arr.indexOf(args) != -1)
{
// console.log(arr.indexOf(args))
arr.splice(arr.indexOf(args), 1)
return destroy(args)
}
// else if(arr.indexOf(args) == -1)
}
for(let i = 1; i < arguments.length; i++)
{
destroy(arguments[i])
}
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; rv:79.0) Gecko/20100101 Firefox/79.0
.
Challenge: Seek and Destroy
Link to the challenge: