Diff Two Arrays - stuck

Hi everyone: I know I’m not supposed to push a boolean value into newArr, but, like the title says, I’m stuck. Thanks.

function diffArray(arr1, arr2) {
  const newArr = [];
  for(let i = 0; i < arr1.length; i++) {
    for(let j = 0; j < arr2.length; j++) {
      if(arr1[i] !== arr2[j]) {
        for(let o = 0; o < false; o++) {      
  return newArr;

Less than what? Seems like you missed something there.

Totally, that’s the issue. I wrote this (arr1[i] === arr2[j]) === false and arr1.hasOwnProperty(arr1[i]) === false , but won’t I just get a boolean value? Here’s where my brain is stuck.

You need to rethink things a little. Why are you pushing false to the array? The problem states that you need to return only the elements that are present in only one array, not in both.

Soooo how would you do this by hand?
You take one element of the first array, then you look at the first element of the second array, then if they are different you… you make another for-loop while the counter is… smaller than “false”? And for each loop your write “false” into the newArray… sorry what?

The first two loops make sense, now you just need to think about when you would add an element to the new array.
However everything that comes after… yeah, no idea what that is supposed to do.

Hi Pavel. This is actually a thread I created. It is better if you create one for you. On the forum’s initial page, click on the button that’s located on the right-hand side called New Topic.

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