Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by paulh

Hi all

I have a large wordlist (over 100K) and im trying to find the best/fastest way to check against the words, i read that "in" is the quickest function but i cnat seem to get it to return correct values :

console.log ("HELLO" in ig.game.word)


The array is in the format:


ig.game.word = [ "HI" , "YO'' , "HELLO"];


Ive tried lots of variations to try to get a true value for HELLO using in, is it possible? IS this the quickest way of checking a large array?

Also, if i had a word :

HELLO

How can i quickly check for

HELL

and

HELLO

Many thanks!

1 decade ago by Mario

i think you have to work with a tree so you cann make quick checks for letters

example:
array[0-25] contains all words with [A-Z]

array[2][0-25] contains all words with [C][A-Z] and so on

so you can easy check with an simple a-z array

HELLO means --> array[ abc[ 'H' ] ] [ abc['E'] ] [ abc['L'] ] [ abc['L'] ] [ abc['O'] ]

1 decade ago by dominic

The in operator only works on Objects, not on Arrays:

var dict = { a: 1, b: 2, c: 3 };
'b' in dict; // true
'z' in dict; // false

Objects also have an hasOwnProperty method. For Arrays, you can use indexOf.

For your specific problem - searching words in large dictionaries - have a look at these two excellent articles from John Resig:
http://ejohn.org/blog/dictionary-lookups-in-javascript/
http://ejohn.org/blog/javascript-trie-performance-analysis/

1 decade ago by paulh

many thanks for the replies, i found this update:

http://ejohn.org/blog/revised-javascript-dictionary-search/#postcomment

im thinking of a number of strings :

3= "onetwoforyou"
4="fourforefiveword"

and a binary search through them might be the quickest way with an average memory overhead?

Now i have to work out what binary search means, lol :-)
Page 1 of 1
« first « previous next › last »