I would like to create all possible words(valid and invalid both) from the letters inputted from the user. For example, the letters are "a,t,e". The answer should be "a,t,e,at,ta,ae,ea,te,et,ate,aet,tea,tae,eta,eat"(No duplicates). I need to do this using javascript or jquery.
I have succeeded in creating all words of length the same as the number of letters.
let genAnagrams= (word, anagram='',anagrams=[])=>{
if(!word){
anagrams.push(anagram);
return;
}
for(var i=0;i<word.length;i++){
anagram+= word[i];
genAnagrams(word.slice(0,i)+ word.slice(i+1),anagram,anagrams);
anagram=anagram.slice(0, anagram.length-1);
}
return anagrams;
};
For input as "a,t,e", expected output would be a,t,e,at,ta,ae,ea,te,et,ate,aet,tea,tae,eta,eat"(No duplicates)