mramine364

subsets

May 30th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function subset(set){
  3.     var res=[], i=0, lim = Math.pow(2,set.length);
  4.     for(;i<lim;i++){
  5.         var n=i, rtmp=[], j=0;
  6.         while(n!=0){
  7.             var x = n%2;           
  8.             if( x==1 )
  9.                 rtmp.push(set[j]);     
  10.             j++;
  11.             n = (n-x)/2;
  12.         }
  13.         res.push(rtmp);
  14.     }
  15.     return res;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment