Why the first solution on "Drop it" challenge works?

Tell us what’s happening: I don’t understand why the first solution posted here: freeCodeCamp Challenge Guide: Drop it - Guide - The freeCodeCamp Forum works because in dropElements([0, 1, 0, 1], function(n) {return n === 1;})) the condition to run the loop returns true for the first element so the method inside should not run, right? Or am I missing something?

  **Your code so far**

function dropElements(arr, func) {
return arr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });

Challenge: Drop it

Link to the challenge:

First element is 0 so the function returns false which is negated by ! so the arr.shift() runs and removes that element.

If the number isnt true, the .shift() delete it, and return the rest even if the rest of the numbers doesnt met the requirements

1 Like