Looks like you actually want the reverse of binary counting; i.e. for binary it would be
0001
0010
0011
but you're flipping it. Which is fine. The following code counts from 0 to the necessary number (16 for a four-letter word), gets the binary representation for each number, reverses it, and outputs the letters of your word for those places where there's a one in the binary representation.
function letterScroller(str) {
var iterations = Math.pow(2,str.length);//iterate from 0 to 2**wordlength
var result = "";
for (i=0;i<iterations;i++) {
//get the binary representation, pad it, and reverse it
var bin = reverse(pad(i.toString(2), str.length));
//loop through binary, adding character of word where there's a 1
for (j=0;j<str.length;j++) {
if (bin.charAt(j)=="1") {
result += str.charAt(j)
} else {
result += "-";
}
}
result += "<br />"; //separate lines with HTML line break
}
return result;
}
function pad(str, length) {
while (str.length < length) {
str="0" + str;
}
return str;
}
function reverse (str) {
return str.split("").reverse().join("");
}