From e2d06d4ca86d20adc3f331e9ff39ba0530fee0ba Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Mon, 26 Feb 2018 10:58:05 +0530 Subject: [PATCH] Update and rename fuzzySearch.md to isSimilar.md --- snippets/{fuzzySearch.md => isSimilar.md} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename snippets/{fuzzySearch.md => isSimilar.md} (81%) 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 ```