Skip to content

Instantly share code, notes, and snippets.

@mitrakmt
Created October 3, 2016 15:00
Show Gist options
  • Save mitrakmt/71f51107dcddd3feac67c999d6811073 to your computer and use it in GitHub Desktop.
Save mitrakmt/71f51107dcddd3feac67c999d6811073 to your computer and use it in GitHub Desktop.
Exploring the programming challenge All Anagrams.
function allAnagrams (str) {
var storage = {};
function recurse(used, avail) {
if(avail.length === 0){
storage[used]=true;
}
for(var i=0; i<avail.length; i++) {
var avail2 = avail.slice(0,i) + avail.slice(i+1);
recurse(used+avail[i], avail2);
}
}
recurse('', str);
return Object.keys(storage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment