Here's something I made quite some time ago. There are probably better ways to do this, although this is what I came up with. Truth be told, it's a poor example of using recursion since it doesn't exit anywhere. If you were to port it to a program like C++, I would convert the recursive function to a WHILE loop.
I have seen online anagram services but I forgot the addresses. All the ones I have seen never returned all the possible words though. They limited themselves to the first 2500 words found, give or take.
A quick Google of "anagrams" should return a lot of sites that do server-side processing of anagrams.
function fncGetSequences( aryBodyTemp, aryHeadTemp) {
if( !aryHeadTemp) {
aryHeadTemp = new Array();
}
for( var index= 0; index< aryBodyTemp.length; index++) {
aryBody = aryBodyTemp;
aryHead = aryHeadTemp;
aryHead = aryHead.concat( aryBody.slice( index, index+1));
aryBody = aryBody.slice( 0, index).concat( aryBody.slice(index+1));
if( aryBody.length == 0) {
document.write( aryHead.join("") + "
");
}
fncGetSequences( aryBody, aryHead);
}
}
// CHANGE LETTERS HERE.
var strSequence = "abcde";
var aryParsed = new Array();
for( index= 0; index< strSequence.length; index++) {
aryParsed[ index] = strSequence.charAt( index);
}
fncGetSequences( aryParsed);