joshaven / string_score

JavaScript string ranking 0 for no match upto 1 for perfect... "String".score("str"); //=> 0.825
MIT License
840 stars 62 forks source link

Faster string query #35

Open pan199612 opened 4 years ago

pan199612 commented 4 years ago

Hello, I think you can use a hash table to speed up the query. 1) Create a hash table of words, with key values as characters, and values as positions of characters。 Word: Hello User Input: eao image

2)Find the character entered by the user: ‘e’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 1.

3) Find the character entered by the user: ‘a’, Find by hash table, find index greater than 1 (you can use binary search) 'A' not found, index does not move

4)Find the character entered by the user: ‘o’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 4.

I'm not familiar with js, I can't implement it with code, I'm really sorry.