Intermidate Algorithms

Tell us what’s happening:
Describe your issue in detail here.
Pls, I am having a hard time deciding what to do. I think I should join both arrays and iterate through it for repetitions but I am stuck on how to nest the iterations

  **Your code so far**

function diffArray(arr1, arr2) {
const newArr = arr1.concat(arr2);
return newArr;

console.log(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/98.0.4758.102 Safari/537.36 Edg/98.0.1108.62

Challenge: Diff Two Arrays

Link to the challenge:

So the problem says that we have to find those entries in the second array that are not in the first array, and those entries in the first array that are not in the second array.

There are many ways of solving this problem:

  1. Concatenate both arrays and remove those duplicated elements (very good solution)
  2. Classical programming: Two for. The first one loops the first array to find elements that are not in the second, and viceversa.
  3. Array filters: use filterfunction to filter out those entries that are already in the other array.

I think your solution is very good. Now you have to remove duplicates. Just google search “remove duplicates js array”.
Here is a good resource:

good luck

1 Like

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