Any better solutions for this challenge ? : 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**
function filteredArray(arr, elem) {
  let newArr = [];
  // Only change code below this line
  for (let i = 0; i < arr.length; i++) {
    if (!arrayHasElem(arr[i],elem)) {
      newArr.push(arr[i]);
    }
  }
  // Only change code above this line
  return newArr;
}

function arrayHasElem(arr,elem){
for (let i = 0; i < arr.length; i++) {
    if (arr[i] === elem) {
      return true;
    }
  }
  return false;
}

console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));

Challenge: Iterate Through All an Array’s Items Using For Loops

Link to the challenge:

You wrote code outside of the “only change code here” section.
The idea is to have nested for loops → meaning what you wrote in a seperate function would just be another for-loop within the first.

1 Like