Intermediate Algorithm Scripting: Diff Two Arrays question

Hi,

I’m working on the Diff Two Arrays question. I have joined the arrays together in a single new array. I then counted the frequency of the numbers and stored the results in an object. I now want to return the results in the object that appear with a frequency of 1. Can anyone help me out with this? Or if this won’t work for the solution I would also like to know. Thanks :slight_smile:

function diffArray(arr1, arr2) {
  var finalArr = [];
  var countObj = {}; 
  var newArr = [...arr1, ...arr2];
  for (var i = 0; i < newArr.length; i++) {
    if (!countObj[newArr[i]]) 
       countObj[newArr[i]] = 0;
       ++ countObj[newArr[i]]; 
    } for (var prop in countObj) {
      if(countObj.hasOwnProperty(1)) {
        finalArr.push(); 
      } return finalArr; 
    }
  }

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

you are checking if the countObj has the property named “1”, not the value of the property
instead you want to loop (with for...in) over the properties and check their value

push needs an argument, right now you are pushing nothing to finalArr

Thanks very much ieahleen!