Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JavaScript-Packer/2fd9b24d3ed2ec95297a to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/2fd9b24d3ed2ec95297a to your computer and use it in GitHub Desktop.
Get all possible combinations and permutations for 8-bit binary. Live demo on http://jsfiddle.net/eur7o7eL/
function possible(e, n, t, r, W) {
if (0 === e.length) {
return [];
}
if (1 === e.length) {
return e[0];
}
n = [], t = possible(e.slice(1));
for (r in t) {
for (W = 0; W < e[0].length; W++) {
n.push(e[0][W] + t[r]);
}
}
return n;
}
alert(possible([ [ "1", "0" ], [ "1", "0" ], [ "1", "0" ], [ "1", "0" ], [ "1", "0" ], [ "1", "0" ], [ "1", "0" ], [ "1", "0" ] ]));
@JavaScript-Packer
Copy link
Author

Minified version:

function e(n,t,r,W,a){if(0===n.length)return[];if(1===n.length)return n[0];t=[],r=e(n.slice(1));for(W in r)for(a=0;a<n[0].length;a++)t.push(n[0][a]+r[W]);return t}alert(e([["1","0"],["1","0"],["1","0"],["1","0"],["1","0"],["1","0"],["1","0"],["1","0"]]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment