mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add either matches helper
This commit is contained in:
parent
c2bb2d9787
commit
adb253d698
1 changed files with 24 additions and 0 deletions
|
|
@ -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 )
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue