diff --git a/snippets/fuzzySearch.md b/snippets/isSimilar.md similarity index 81% rename from snippets/fuzzySearch.md rename to snippets/isSimilar.md index a4cb51430..add2e6c02 100644 --- a/snippets/fuzzySearch.md +++ b/snippets/isSimilar.md @@ -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 ```