Merge pull request #610 from kriadmin/master

[ADD] isSimilar (archive)
This commit is contained in:
Angelos Chalaris
2018-02-26 17:30:08 +02:00
committed by GitHub
2 changed files with 1058 additions and 1051 deletions

View File

@ -0,0 +1,19 @@
### isSimilar
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 ? true : false;
```
``` js
isSimilar('rt','Rohit'); // true
isSimilar('tr','Rohit'); // false
```

File diff suppressed because it is too large Load Diff