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!
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.
@camperextraordinaire, 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!
Thanks for the tip! Much appreciated!
1 Like