From e21bff8504a7c9cf2846ecfbdd1a63a74735d330 Mon Sep 17 00:00:00 2001 From: Felix Wu Date: Fri, 14 Sep 2018 12:58:54 +0200 Subject: [PATCH] fix isSimilar --- snippets_archive/isSimilar.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/snippets_archive/isSimilar.md b/snippets_archive/isSimilar.md index 7ed53b2ae..e6b2a8360 100644 --- a/snippets_archive/isSimilar.md +++ b/snippets_archive/isSimilar.md @@ -5,15 +5,14 @@ Determines if the `pattern` matches with `str`. Use `String.toLowerCase()` to convert both strings to lowercase, then loop through `str` and determine if it contains all characters of `pattern` and in the correct order. Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db53428247e741b9efe2cde9667050c/code/fts_fuzzy_match.js#L18). -``` js +```js const isSimilar = (pattern, str) => [...str].reduce( (matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 ) === pattern.length ? true : false; ``` - -``` js +```js isSimilar('rt','Rohit'); // true isSimilar('tr','Rohit'); // false ```