Trouble with if statement in Iterate through All an Array's items challenge

Trouble with if statement in Iterate through All an Array's items challenge
0

#1

I’ve got myself pretty turned around with the Basic Data Structures: Iterate through all an array’s items using for loops challenge:

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops

function filteredArray(arr, elem) {
  let newArr = [];
  // change code below this line
  
  for(let i = 0; i < arr.length; i++) {
  
        if (arr[i].indexOf(elem) < 0){
          newArr.push(arr[i]);
        }

  }
  // change code above this line
  return newArr;
}

filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18);

I can’t seem to get the current sub-array pushed to my newArr; also, I’m not convinced my if statement is running enough times.

Any guidence much appreciated!


#2

Hey @paul_dee,
If you are not convinced about this, use console.log() in chrome console and see your result.
Most of the time i get my answers and mistakes by using console.log().
See if it helps you.


#3

When you run the code you posted, are you failing any tests?


#4

@randelldawson, I feel like a proper fool…it passed the tests. I was trying to get it work using my regular code editor and…who knows what happened but it wasn’t returning the values i wanted. It is now and it passed the tests.

I think that is officially a signal that I need to take a break!


#5

Thanks for the tip! Much appreciated!