From 8a45b51dc3817cb11720d06e64690713ec7c7d10 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 16 Apr 2020 11:08:26 +0300 Subject: [PATCH] Remove isSimilar --- snippets_archive/isSimilar.md | 25 ------------------------- test/isSimilar.test.js | 11 ----------- 2 files changed, 36 deletions(-) delete mode 100644 snippets_archive/isSimilar.md delete mode 100644 test/isSimilar.test.js diff --git a/snippets_archive/isSimilar.md b/snippets_archive/isSimilar.md deleted file mode 100644 index 785ab130e..000000000 --- a/snippets_archive/isSimilar.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: isSimilar -tags: string,intermediate ---- - -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 -const isSimilar = (pattern, str) => - [...str].reduce( - (matchIndex, char) => - char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() - ? matchIndex + 1 - : matchIndex, - 0 - ) === pattern.length; -``` - -```js -isSimilar('rt','Rohit'); // true -isSimilar('tr','Rohit'); // false -``` \ No newline at end of file diff --git a/test/isSimilar.test.js b/test/isSimilar.test.js deleted file mode 100644 index 22f069283..000000000 --- a/test/isSimilar.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const {isSimilar} = require('./_30s.js'); - -test('isSimilar is a Function', () => { - expect(isSimilar).toBeInstanceOf(Function); -}); -test('isSimilar returns true', () => { - expect(isSimilar('rt', 'Rohit')).toBeTruthy(); -}); -test('isSimilar returns false', () => { - expect(isSimilar('tr', 'Rohit')).toBeFalsy(); -});