Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Last active November 5, 2022 14:06
Show Gist options
  • Save Rudxain/c5f105a0f0f33f370e45349cab08ac9f to your computer and use it in GitHub Desktop.
Save Rudxain/c5f105a0f0f33f370e45349cab08ac9f to your computer and use it in GitHub Desktop.
Some "missing" JS logical operators defined as functions
'use strict'
const
/**Python's `bool` ported to JS (doesn't work quite the same) */
bool = x => x == true,
logicXOR = (a, b) => !a != !b ? a : b,
logicXNOR = (a, b) => !a == !b ? a : b,
logicXORalt = (a, b) => !a != !b ? a || b : a && b,
logicXNORalt = (a, b) => !a == !b ? a || b : a && b,
logicIMPLY = (a, b) => !a || !!b ? a : b,
logicNIMPLY = (a, b) => !!a && !b ? a : b
//LICENSE: https://unlicense.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment