Last active
June 6, 2021 09:09
-
-
Save lancejpollard/817bb054011ca59b54c1444bdc41fb75 to your computer and use it in GitHub Desktop.
Compute the Powerset of a Set in JavaScript
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
const computePowerSetOfSetOfNumbers = (set) => { | |
const powerset = [] | |
const n = set.length | |
let i = 0 | |
while (i < n) { | |
let x = n | |
while (x > i) { | |
powerset.push(set.slice(i, x)) | |
x-- | |
} | |
i++ | |
} | |
return powerset | |
} | |
const set = [1, 2, 3, 4, 5] | |
const powerset = computePowerSetOfSetOfNumbers(set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment