!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:
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?
crisvoss77:
it just means !5+5=10
I don’t know what you think that expression means. Can you explain more? I don’t think that you know what the ! does
The logical NOT (!) (logical complement, negation) operator takes truth to
falsity and vice versa. It is typically used with boolean (logical)
values. When used with non-Boolean values, it returns false if its single
operand can be converted to...
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.
system
Closed
December 22, 2022, 3:37pm
10
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.