Why dropIt from Algorithm Scripting , works for ">" but not " <"?

dropIt(array,func) {
while(array.length>0 && !func(array[0]))array.shift();
return array;

console.log(dropIt([1,2,3,4], n=>n<3))  // doesn't work

// but

console.log(dropIt([1,2,3,4], n=>n>3))  // does 

And, I’m wondering why!!

What do you mean by “doesn’t work”? What do you expect to happen vs. what happens?

Thank you so much for looking into this, I really appreciate it very much.

Now, what I’m expecting is, when checking for n<3, it shows all items in array, but I’m expecting it to show elements <3 only (e.g. [1,2])!!

The loop only runs if the condition is true.
The first element in the array is 1.
1 is less than 3, so !(1 < 3) is false.
Loop doesn’t run.
Return the original array with nothing removed.


Thanks, I wasn’t considering "!"for " < "operation check. Thank you for helping me understand, much appreciated :slight_smile: