78

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?

Harry
  • 52,711
  • 71
  • 177
  • 261

2 Answers2

118

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
Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
Blender
  • 289,723
  • 53
  • 439
  • 496
13

In CoffeeScript, NOT can be denoted as ! or not

if err && !(user in moderators)

if err && user not in moderators

would both work.

bobbybee
  • 1,758
  • 1
  • 16
  • 27