RockPaperScissors

LizardSpock

Create And,Or of Multiple Booleans

| Comments

To reduce an array of Booleans to a single Boolean using enumerables reduce method:

[true, true, true].reduce( :| ) ## OR
=> true
[true, true, true].reduce( :& ) ## AND
=> true

[false, false, false].reduce( :| ) ## OR
=> false
[false, false, false].reduce( :& ) ## AND
=> false

[true, true, false].reduce( :| ) ## OR
=> true
[true, true, false].reduce( :& ) ## AND
=> false

Checksums (XOR)

[false, false].reduce( :^ ) ## XOR
=> false
[false, true ].reduce( :^ ) ## XOR
=> true
[true, false ].reduce( :^ ) ## XOR
=> true
[true, true  ].reduce( :^ ) ## XOR
=> false

Comments