combinations javascript

function combinations(items){
    var totalItems    =    items.length;
    for(i=0;i        var result    =    Number(i).toString(2);
        result    =    ("0000" + result).substr(-4,4);
        var combination    =    "";
        for(j=0;j            if(result.charAt(j)=="1"){
                combination+=items[j]+",";
            }
        }
          console.log(combination.substring(0,combination.length-1));
    }
}

var items=["a","b","c","d"];
combinations(items);

Truth Table based formula deciphering: http://booleanbot.com/

Comments

Popular posts from this blog

How to get started with Vue in under a minute?

aigiri nandini - Brodha V you rock