A community for students.
Here's the question you clicked on:
 0 viewing
ganeshie8
 one year ago
how does this powerset function work
```
function power_set(set) {
var power_set=[];
for(i=0; i<(1<<set.length); i++) {
var subset=[];
for(j=0; j < set.length; j++) {
(i&(1<<j)) && subset.push(set[j]);
}
power_set.push(subset);
}
return power_set;
}
```
https://jsfiddle.net/ng1hL2Ls/
ganeshie8
 one year ago
how does this powerset function work ``` function power_set(set) { var power_set=[]; for(i=0; i<(1<<set.length); i++) { var subset=[]; for(j=0; j < set.length; j++) { (i&(1<<j)) && subset.push(set[j]); } power_set.push(subset); } return power_set; } ``` https://jsfiddle.net/ng1hL2Ls/

This Question is Closed

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2Haha i don't like javascript either as my fav is perl

nincompoop
 one year ago
Best ResponseYou've already chosen the best response.1I think the result is pretty good, I just never liked Js because it always looks cluttered. power set is to provide all the subsets of a set. recursive and nonrecursive

nincompoop
 one year ago
Best ResponseYou've already chosen the best response.1P {a, b, c} {} {a} {b} {c} {a,b} ... and so on and so forth http://rosettacode.org/wiki/Power_Set#JavaScript

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2wow that looks more compact! im still trying to figure out get how it works

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2looks the python powerset function is also using the leftshift and the logical and
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.