Add either matches helper

This commit is contained in:
Sam Carlton 2021-03-04 20:44:47 -06:00
parent c2bb2d9787
commit adb253d698

View file

@ -4,3 +4,27 @@ export function matchesWholeWord (needle, haystack) {
return new RegExp('\\b' + needle + '\\b').test(haystack)
}
export function eitherMatches (stringA, stringB) {
const stringALength = stringA.length
const stringBLength = stringB.length
// If string lengths are equal
// then just compare the equality of the strings
if (stringALength === stringBLength) {
// console.log('Strings are equal length', stringA, stringB)
return (stringA === stringB)
}
// If string A is larger
// then find string B within it
if (stringALength > stringBLength) {
// console.log('String A is bigger', stringA, stringB)
return matchesWholeWord( stringB, stringA )
}
// If string B is larger
// then find string A within it
// console.log('String B is bigger', stringA, stringB)
return matchesWholeWord( stringA, stringB )
}