MATHEMATICS
ALGORITHMS
Write a function that returns all of the sublists of a list/array.
Example:
power([1,2,3]);=>[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
For more details regarding this, see the power set entry in wikipedia.
const power = array => {
let results = [[]]
for (let i = 0; i < array.length; i++) {
let len = results.length
for (let j = 0; j < len; j++) {
results.push([...results[j], array[i]])
}
}
return results
}