Files
30-seconds-of-code/snippets/fuzzySearch.md
2018-02-19 21:21:10 +05:30

633 B

fuzzySearch

Determines if the patrn matches with str

Loops through str and determines if it contains all characters of patrn and in the correct order. Both the strings are converted to lower case.

Taken from here.

const fuzzySearch = (pattern, str) =>
	[...str].reduce(
		(acc, char) => char.toLowerCase() === (pattern[acc]  || '').toLowerCase() ? acc + 1 : acc, 0
	) === pattern.length ? true : false;
fuzzySearch('rt','Rohit'); // true
fuzzySearch('tr','Rohit'); // false