Question:
JavaScript anagrams/permutations with JSON?
§©®Î¶†Δ®
2007-01-30 16:28:16 UTC
From within JavaScript, I need an array of all of the words that can be made from some random letters. Also, I need all of the possible combinations of letters (even if they are not words.) It would be great to find a code example written in JavaScript that (quickly) calculates string permutations. However, it doesn't seem too practical to place an entire dictionary into a page for the anagram part; so I am thinking it would be best to use JSON and download the results. Is there a public web service that will accept a string (let's say up to seven characters since 7! or 5040 permutations is not unreasonable) and return all anagrams and/or permutations of that string in JSON format?
Three answers:
jake cigar™ is retired
2007-01-30 17:23:01 UTC
playing scrabble? I know of several sites where I can enter my hand and get back the best words!!!

http://www.google.com/search?q=dictionary+scrabble+anagram

will get you to them!
Kookiemon
2007-01-31 00:47:08 UTC
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);
2014-06-24 09:44:04 UTC
Maybe you need custom javascript parsing. For example, I am using Smartface App Studio for Standart JSON Parsing with their JSON wizard tools however I may use custom parsing editor using their scripting editor. http://www.smartface.io/benefits-app-studio/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...