Advertisement
Guest User

Untitled

a guest
May 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. const input = ['a', 'b', 'c'];
  2.  
  3. const possibilities = Math.pow(2, input.length);
  4.  
  5. const allsets = [];
  6.  
  7. for(let i = 0; i < possibilities; i ++) {
  8. const set = [];
  9. for( let j =0; j < input.length; j ++) {
  10. const stuff = Math.pow(2, j);
  11. if (i & stuff) {
  12. set.push(input[j]);
  13. }
  14. }
  15. allsets.push(set);
  16. }
  17.  
  18. console.log(allsets.sort((a, b) => a.length - b.length))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement