2

I'd like to find JavaScript libraries or general algorithms (write my own library) to be able to match strings in my array with over 2000 strings. In Discord you can leave out letters and it'll still be able to match against someone so I'd like to be able to do the same. For example, searching "js" would match against "JavaScript" in my word bank. Or searching "ccard" would match against "credit card".

I would like the matching results to be ranked based on entropy or something. For example, searching "nattorice" would rank the result of "Natto with Rice" to be better than "Natural Cotton Fabric Selection" because the letters hit are closer grouped together rather than spread apart.

I don't know what to search in google to help me figure out some implementation that is efficient.

Unmitigated
  • 76,500
  • 11
  • 62
  • 80
secretlyrice
  • 305
  • 1
  • 6
  • 1
    Take a look at the following https://stackoverflow.com/questions/10473745 and https://stackoverflow.com/questions/1609742 which reference a few algorithms for comparing string values for their likeness. – Trentium Jun 29 '20 at 00:49
  • 3
    You can try [`fuzzysort`](https://github.com/farzher/fuzzysort). – Unmitigated Jun 29 '20 at 00:55
  • 3
    @hev1 I tried out that fuzzy sort library and it's everything I wanted. Thank you – secretlyrice Jun 29 '20 at 01:17

1 Answers1

3

You can use the fuzzysort library to do this.

Unmitigated
  • 76,500
  • 11
  • 62
  • 80