So I thought I had this challenge sorted, quite a good one.
I believe I used a nested for loop properly so each element inside every array inside the outer array is checked.
Your code so far
function filteredArray(arr, elem) {
let newArr = [];
for ( var row = 0 ; row < arr.length ; row ++ ) {
for (var col = 0; col< arr[row].length; col++) {
if (arr[row][col] == elem) {
delete arr[row][col];
}
}
}
newArr = arr;
// change code above this line
return newArr;
}
// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops
so
if (arr[row][col] == elem) {
delete arr[row][col];
}
is using delete a legit way of getting rid of elem = 3 if it exists in any of the arrays?
Would be great if .pop() was able to specify what to remove but alas it can only remove the last element of an array.
I also think
newArr = arr;
may not be in the correct position.
Please give some pointers if I’m anywhere close - or not. Thansk in advance