Algorithm Help Diff Array

I’m wondering why my arr4 does not contain unique elements from 1 array.

  **Your code so far**

function diffArray(arr1, arr2) {
let arr3 = arr1.concat(arr2);
let count = 0;
let arr4 = [];
//count numbers if they are 1 then add them to a new arr called arr4
for (let i = 0;   i < arr3.length; i++) {
  for (let j = 0; j < arr3.length; j++) {
    if (arr3[i] === arr3[j]) {
if (count === 1) {
return arr4;

console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Diff Two Arrays

Link to the challenge:

Could you explain how it’s supposed to work? Maybe with some example?

It’s supposed to count the unique elements in the combined array then when the count is 1 append those numbers to a new array called arr4, but when I return arr4 it does not seem to return anything, when in fact it’s supposed to return [4]. I might have to use another data structure to do a count like a dictionary.

Take a look what’s the value of count before the it’s checked if it’s 1.

the count prints the numbers 1 to 17.

With the code from original post it should be only 17. Are you able to figure out why that’s happening?

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