Intermediate Algorithm Scripting - Drop it - vmuso4NiJEi9tpzWhEMGQ

Tell us what’s happening:
Hey guys, basically I don’t pass 2 tests. the second and last one, could anyone explain me why please? Thank you :slight_smile:

  **Your code so far**
function dropElements(arr, func) {
let firstNumber;
let newArr = [];
while(arr.length !== 0) {
  firstNumber = arr.shift();
  console.log(firstNumber)
  console.log(arr)
  if (func(firstNumber)) {
    newArr.push(firstNumber);
  }
}
return newArr
}

dropElements([0, 1, 0, 1], function(n) {return n === 1;})
/*
iterate through arr;
remove each element that is arr[0];
check if func passes with those numbers;
if yes push into array, if no leave it as it is.
return array with passed numbers if nothing is passed rteurn an empty arr;
*/
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Drop it

Link to the challenge:

Then return the rest of the array once the condition is satisfied, otherwise, arr should be returned as an empty array.

What is your function returning?

1 Like

I think I understood what you mean, I’ll work it from here ty.

I would make sure you know how to do this without destroying the old array

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