Last active
November 10, 2015 21:40
-
-
Save sandro-pasquali/87d1fb0ccd34de09d914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function powerSet(list) { | |
var set = []; | |
var listSize = list.length; | |
var combinationsCount = 1 << listSize; | |
var combination; | |
var i = 1; | |
var j; | |
for(; i < combinationsCount; i++ ) { | |
var combination = []; | |
for(j=0; j<listSize; j++) { | |
if(i & 1 << j){ | |
combination.push(list[j]); | |
} | |
} | |
set.push(combination); | |
} | |
return set; | |
} | |
console.log(powerSet(['a','b','c','d'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment