Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 29, 2015 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavaScript-Packer/66bbd4e64b246fa6384c to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/66bbd4e64b246fa6384c to your computer and use it in GitHub Desktop.
An anagram generator in JavaScript I set up for possible DNA sequencing patterns
function allAnagrams(r) {
var n, a, t, l, e, s;
if (r.length < 2) {
return [ r ];
}
for (n = [], a = 0; a < r.length; a++) {
for (t = r[a], l = r.substr(0, a) + r.substr(a + 1, r.length - 1), e = allAnagrams(l),
s = 0; s < e.length; s++) {
n.push(t + e[s]);
}
}
return n;
}
document.write(allAnagrams("ACCGAT"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment