Update and rename fuzzySearch.md to isSimilar.md

This commit is contained in:
Rohit Tanwar
2018-02-26 10:58:05 +05:30
committed by GitHub
parent acc8aa054f
commit e2d06d4ca8

View File

@ -1,4 +1,4 @@
### fuzzySearch
### isSimilar
Determines if the `pattern` matches with `str`
@ -6,7 +6,7 @@ Loops through `str` and determines if it contains all characters of `pattern` an
Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db53428247e741b9efe2cde9667050c/code/fts_fuzzy_match.js#L18).
``` js
const fuzzySearch = (pattern, str) =>
const isSimilar = (pattern, str) =>
[...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
) === pattern.length ? true : false;
@ -14,6 +14,6 @@ const fuzzySearch = (pattern, str) =>
``` js
fuzzySearch('rt','Rohit'); // true
fuzzySearch('tr','Rohit'); // false
isSimilar('rt','Rohit'); // true
isSimilar('tr','Rohit'); // false
```