Did you try the following:
function range(til) {
var x = 0, xs = [];
while (x < til) xs.push(x++);
return xs;
}
function generate(n) {
return range(Math.pow(2, n));
}
Now you can generate all the numbers from 0 to 7 as follows:
var xs = generate(3);
If you want it in string format then use the following function instead:
function replicate(n, x) {
var i = 0, xs = [];
while(i++ < n) xs.push(x);
return xs;
}
function generateBitmasks(n) {
var padding = replicate(n, '0').join('');
return range(Math.pow(2, n)).map(function (x) {
return (padding + x.toString(2)).slice(-n);
});
}
Now you can get the list of bitmasks for 0 to 7 as follows:
var bitmasks = generateBitmasks(3);
I hope that helped.