Hi can you tel me about this pleas?

Tell us what’s happening:

Your code so far


function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
return newArr;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36.

Challenge: Diff Two Arrays

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays

Hi @masoud76, welcome to the forum.
To solve these types of problem, I advise you to first reason with pen and paper.
They are asking you to return an array with the elements that are included in only one of the 2 arrays.
This element could be either present in the first array and not present in the second or the other way around.

Solve it in small steps, each one built on the previous step.

  1. Given an element of the first array, how would you check that the same element is or isn’t present in the other array?
  2. After that, you have to remember that the check has to be done for all the elements in array 1.
  3. And after that, you have to remember to also check the elements of array 2 that could or could not be present in array 1.
1 Like