Skip to content

Instantly share code, notes, and snippets.

@Alynva
Last active February 25, 2022 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alynva/d36568d3b4839584a520ee1babec663b to your computer and use it in GitHub Desktop.
Save Alynva/d36568d3b4839584a520ee1babec663b to your computer and use it in GitHub Desktop.
Operators && and || rewritten without using the operator itself
const and = (...args) => args.every(x => x)
const and = (a, b) => !!(!!(a || b) ^ !!a ^ !!b)
const and = (...args) => args.reduce((a, b) => !!(!!(a || b) ^ !!a ^ !!b), true)
const and = (...args) => args.length ? args.shift() ? and(...args) : false : true
const or = (...args) => args.some(x => x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment