I have an array of Strings in JavaScript. I am trying to develop a function that
- Takes a substring as an input.
- Searches through the array.
- Returns strings from the array close to the substring. The list will be provided as suggestions to the caller.
For example:-
Array contains the below entries.
Hello
What is hello
World
Spacearenotthereinthishello
HELLO
Highway to hell
JavaScript
StackOverflow
I invoke the function as shown below
var result[] = searchFunc('hell');
The result array should contain
Hello
What is hello
Spacearenotthereinthishello
HELLO
Highway to hell
It is possible that the array could contain atleast 100 strings ( or more). I am looking for a scalable solution.
Initially, i figured i should sort and then do a binary search but its cumbersome to do if you wanna pull of all the suggestions from the master array for a particular string input. I am looking for algorithms that can help me achieve a faster search. I am not that worried about insertion timecomplexity in master array.
I did look up multiple stack overflow posts. They do speak about searching a big book for specific strings. None of them talk about returning suggestions from an array for a substring.
Your help is appreciated.