Created
October 3, 2016 15:00
-
-
Save mitrakmt/71f51107dcddd3feac67c999d6811073 to your computer and use it in GitHub Desktop.
Exploring the programming challenge All Anagrams.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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