Diff Two Arrays

function diffArray(arr1, arr2) {


const newArr = arr1.concat(arr2);

let difference = newArr.filter(x => newArr.indexOf(x) === newArr.lastIndexOf(x));

  
  return difference;
}

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

I managed to solve this problem but I couldn’t do it without looking up certain things on google. I needed a reminder of how to use concat and I needed a reminder that indexOf and lastIndexOf basically indicate where the values start and end in a string. And concat combines two different arrays and makes them one. I already knew how to set up the syntax in the filter method. But is it bad that I needed to search things up in order to complete this solution?

Developers have to look things up all the time. Its impossible to remember all of this stuff. I look up things frequently at work when I am working with something ai havent used in a while. Its just a part of it, but the important thing is you’re not looking things up before trying to solve it on your own.

1 Like

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