coffeescript check if not in array

Coffeescript

Coffeescript Problem Overview


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?

Coffeescript Solutions


Solution 1 - Coffeescript

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 - Coffeescript

In CoffeeScript, NOT can be denoted as ! or not

if err && !(user in moderators)

if err && user not in moderators

would both work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarryView Question on Stackoverflow
Solution 1 - CoffeescriptBlenderView Answer on Stackoverflow
Solution 2 - CoffeescriptbobbybeeView Answer on Stackoverflow