This is a JavaScript function that returns ALL the possible combinations of whatever word the user enters. I am looking to clean this code up a bit...any and all suggestions are welcome!
function allanagramsallAnagrams (word) {
if (word.length < 2) {
return [word];
} else {
var allanswersallAnswers = [];
for (var i = 0; i < word.length; i++) {
var letter = word[i];
var shorterwordshorterWord = word.substr(0, i) + word.substr(i + 1, word.length - 1);
var shortwordarrayshortwordArray = allanagramsallAnagrams(shorterwordshorterWord);
for (var j = 0; j < shortwordarrayshortwordArray.length; j++) {
allanswersallAnswers.push(letter + shortwordarray[j]shortwordArray[j]);
}
}
return allanswers;allAnswers;
}
}
allanagramsallAnagrams("")