Basic Data Structures - Iterate Through All an Array's Items Using For Loops

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
yippee I succeeded too far. I had been making nested arrays disappear and figured that was wrong and untidy. Now I see it was right somewhere probably at some time so will go back. This here removes the (arr,elem) elem from a nested array. The question is to remove the nested array with elem in it. Should be easier. Now to prove that too myself.

function filteredArray(arr, elem) {
  let newArr = [];
  // Only change code below this line
for(let i=0; i<arr.length; i++){ 
    if (arr[i].indexOf(elem)>=0){
      let k=arr[i].indexOf(elem)
      arr[i].splice(k,1);
    
  } 
}newArr=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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57

Challenge: Basic Data Structures - Iterate Through All an Array’s Items Using For Loops

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.