coffeescript check if not in array
Here's something simple to check if user is in moderator. But I want to check if user is not in moderator.
if err && user in moderators
return
Intuitively it would be like this
if err && user isnt in moderators
return
But obviously this doesn't work. What's the best way to do it?
Solution 1:
isnt
is the opposite of is
, which is the triple equals sign. Just negate the in
:
if err and user not in moderators
return
or, using postfix if:
return if err and user not in moderators
Solution 2:
In CoffeeScript, NOT can be denoted as ! or not
if err && !(user in moderators)
if err && user not in moderators
would both work.