From adb253d6980035a2a7654fa8987a850220f09860 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Thu, 4 Mar 2021 20:44:47 -0600 Subject: [PATCH] Add either matches helper --- helpers/matching.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/helpers/matching.js b/helpers/matching.js index 0ad101c..cb754e5 100644 --- a/helpers/matching.js +++ b/helpers/matching.js @@ -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 ) +}