javascript - How to search array of strings and produce suggestive results -


i have array of strings in javascript. trying develop function

  1. takes substring input.
  2. searches through array.
  3. 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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -