Intermediate Algorithm Scripting - Diff Two Arrays

why it is printing to me undefined here

function diffArray(arr1, arr2) {
  const newArr = [];
  


  for(let i = 0; i < arr1.length; i++){
    if(!arr1.includes(arr2[i])){
      newArr.push(arr2[i])
  // console.log(arr1);
  // console.log(arr2);
    }
  }

  
    for(let i = 0; i < arr2.length; i++){
    if(!arr2.includes(arr1[i])){
      newArr.push(arr2[i])
  // console.log(arr1);
  // console.log(arr2);
    }
  }

  
  return newArr;


}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Intermediate Algorithm Scripting - Diff Two Arrays

Check what you are pushing here

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.