mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
30 lines
920 B
JavaScript
30 lines
920 B
JavaScript
|
|
// Match whole word
|
|
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 )
|
|
}
|