Question about the drop it problem

!func(arr[0])) what does this mean?

  **Your code so far**
function dropElements(arr, func) {
while (arr.length > 0 && !func(arr[0])) {
  arr.shift();
}
return arr;
} 

console.log(dropElements([0, 0, 1, 2], function(n) {return n >= 3;}))
  **Your browser information:**

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

Challenge: Drop it

Link to the challenge:

Do you know what ! does?

Yeah it just means !5+5=10
Returns false

Im wondering how it makes sense with !func(arr[0]) means like when when n>3 and arr[0] is 2 does the function stop?

I don’t know what you think that expression means. Can you explain more? I don’t think that you know what the ! does

let a = 2;
console.log(!(a>1))
it would return false
it’s the opposite of it being true !before a variable is stating if !a>5 and a is 6 its gonna be false because of the exclamation point. That’s how I see !.

what im trying to understand is what does this code mean func(arr[0])) is it to see if arr[0] is not >=3 because of the !

Is the ! in the problem stating that if the function is not true than its shifted out of the array?

Yup. The ! negates the truthiness of the result of the function call.

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