I'm trying to make a JavaScript that calculate all possible letter combinations.
I've made this so far:
var input = window.prompt("What to calculate?", "");
var letters = input;
var combi = [];
var temp = "";
var letLen = Math.pow(2, letters.length);
for (var i = 0; i < letLen; i++){
temp = "";
for (var j = 0; j < letters.length; j++){
if ((i & Math.pow(2, j))){
temp += letters[j];
}
if (temp !==""){
combi.push(temp);
}
}
document.write(combi.join(" "));
alert(combi.length);
The result is: r g rg b rb gb rgb
However, there are more possible combinations like bgr brg br gr bg
What do I have to chance in my code to show all possible combinations and not some of them?
Thanks in advance.