Skip to content

Instantly share code, notes, and snippets.

@Oppodelldog
Created August 17, 2015 07:52
Show Gist options
  • Save Oppodelldog/2d531a84069e12ba9d8b to your computer and use it in GitHub Desktop.
Save Oppodelldog/2d531a84069e12ba9d8b to your computer and use it in GitHub Desktop.
Evaluate all possible combinations of array items
var arr = ["a","b","c","d","e","f","g","h","i","j"];
for(i = 0; i <= Math.pow(2,arr.length)-1; i++){
var mask = i;
console.log("-------------------------------------" + mask);
var combination = "";
for(y=0; y<arr.length; y++){
if((mask & Math.pow(2,y)) == Math.pow(2,y)) combination += " " + arr[y];
}
console.log(combination);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment