SHARE
TWEET

Untitled

a guest May 15th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top