npm.io
1.0.0 • Published 7 years ago

tiny-xor

Licence
MIT
Version
1.0.0
Deps
0
Size
1 kB
Vulns
0
Weekly
0

tiny-xor

a lot of times i want to see if one of two or more variables evaluates to true based on some function but not all of them and not none of them. that's xor, but sometimes writing xor logic inline muddies things up.

install

npm i tiny-xor

use

const xor = require('tiny-xor')

function isTeen (age) {
  return age > 12 && age < 20
}

// wanting to see if one person is a teenager
let bob = 12
let harry = 13
let john = 14
let sarah = 20

console.log(xor([bob, harry, john, sarah], isTeen)) // false

console.log(xor([bob, harry, sarah], isTeen)) // true

console.log(xor([bob, sarah], isTeen)) // false

license

MIT