Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const input = ['a', 'b', 'c'];
- const possibilities = Math.pow(2, input.length);
- const allsets = [];
- for(let i = 0; i < possibilities; i ++) {
- const set = [];
- for( let j =0; j < input.length; j ++) {
- const stuff = Math.pow(2, j);
- if (i & stuff) {
- set.push(input[j]);
- }
- }
- allsets.push(set);
- }
- console.log(allsets.sort((a, b) => a.length - b.length))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement