Skip to content

Instantly share code, notes, and snippets.

@antenando
Forked from yarwelp/truth_table.js
Created May 13, 2016 15:30
Show Gist options
  • Save antenando/41affe31adee16a651d7de301537f80f to your computer and use it in GitHub Desktop.
Save antenando/41affe31adee16a651d7de301537f80f to your computer and use it in GitHub Desktop.
Truth table (JavaScript)
/* js-truth_table
*
* file: truth_table.js
*
* Copyright (c) 2011, Erik Nordstroem <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
var row = [], values = ["a", "b", "c"]
for (var i = (Math.pow(2, values.length) - 1) ; i >= 0 ; i--) {
for (var j = (values.length - 1) ; j >= 0 ; j--) {
row[j] = (i & Math.pow(2,j)) ? true : false
}
print(row)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment