javascript - How to search array of strings and produce suggestive results -
i have array of strings in javascript. trying develop function
- takes substring input.
- searches through array.
- returns strings array close substring. list provided suggestions caller.
for example:-
array contains below entries.
hello hello world spacearenotthereinthishello hello highway hell javascript stackoverflow i invoke function shown below
var result[] = searchfunc('hell');
the result array should contain
hello hello spacearenotthereinthishello hello highway hell it possible array contain atleast 100 strings ( or more). looking scalable solution.
initially, figured should sort , binary search cumbersome if wanna pull of suggestions master array particular string input. looking algorithms can me achieve faster search. not worried insertion timecomplexity in master array.
i did multiple stack overflow posts. speak searching big book specific strings. none of them talk returning suggestions array substring.
your appreciated.
yourarray.filter() job. quick prototype:
var results = arrayname.filter(function(value) { return value.tolowercase().indexof(searchstr.tolowercase()) >= 0; });
Comments
Post a Comment