Tell us what’s happening
I have iterated through the nested array and removed the elem argument and on the console it displayed the new array which is [ [ [ 2 ], [ 1, 6 ], [ 13, 26 ], [ 19, 9 ] ] ] but i am not still passing the test can someone please tell me what i’m doing wrong
Your code so far
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for (let i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] == elem) {
arr[i].splice(j, 1)
}else{
if (arr[i] == elem) {
arr[j].splice(i, 1); i--
}
}
}
}
}
newArr.push(arr)
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Challenge: Basic Data Structures - Iterate Through All an Array’s Items Using For Loops
Link to the challenge: