Why arr return undefined recursive function

Tell us what’s happening:
I checked the code with pythontutor online ide, program works but at end instead of returning arr it return undefined

See the gif below

Your code so far

function destroyer(arr,d1,d2) {
//let newArr= arr.slice();
if(arr.indexOf(d1)===-1 && arr.indexOf(d2)==-1){
  return arr;
  let index1 = arr.indexOf(d1);
  let index2 = arr.indexOf(d2);


console.log(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/79.0.3945.88 Safari/537.36.

Challenge: Seek and Destroy

Link to the challenge:

look at where your return statement is
for recursion to work the function always needs to return something , and you need to do something with the returned value
do you do something with the returned value of your function calls?

1 Like

Thanks i got answer, can you tell me one more thing how to take unknown number of arguments
function destroyer(arr,d1,d2) instead of d1 and d2 if i want to take unknow number of args how do i take it.
I tried to find the solution i got this. i am not able to relate properly

var print_names = function(...names) {
    for (let i=0; i<names.length; i++) console.log(names[i]);

Please help

I got it thanks, don’t answer