Hello. I have this code:
function filteredArray(arr, elem) {
let newArr = [];
let index2;
console.log(elem);
// change code below this line
for (let i=0; i < arr.length; i++){
for(let y=0; y < arr[i].length; y++){
let index = arr[i].indexOf(elem);
if(index >=0){
let index2 = arr.indexOf(arr[i]);
}
if(index2 >=0){
arr.splice(index2, 1);
}
}
}
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));
In the console I get: 3
[ [ 3, 2, 3 ], [ 1, 6, 3 ], [ 3, 13, 26 ], [ 19, 3, 9 ] ]
and I get errors:
// running tests
filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)
should return
[ [10, 8, 3], [14, 6, 23] ]
filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2)
should return
[ ["flutes", 4] ]
filteredArray([ ["amy", "beth", "sam"], ["dave", "sean", "peter"] ], "peter")
should return
[ ["amy", "beth", "sam"] ]
filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)
should return
[ ]
Any ideas of what I am doing wrong?