Last active
August 18, 2022 16:25
-
-
Save Mustafa-Omran/91cb549f0a9905527845ceb723c7d852 to your computer and use it in GitHub Desktop.
Intersection of two Strings JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private itersection(textOne: string, textTwo: string): string { | |
let textOneIndex: number = 0; | |
let textTwoIndex: number = 0; | |
let matchedText: string = ''; | |
textOne = textOne.toLowerCase(); | |
textTwo = textTwo.toLowerCase(); | |
while (textOneIndex < textOne.length && textTwoIndex < textTwo.length) { | |
if (textOne[textOneIndex] < textTwo[textTwoIndex]) { | |
textOneIndex++; | |
} else if (textTwo[textTwoIndex] < textOne[textOneIndex]) { | |
textTwoIndex++; | |
} else { | |
matchedText = `${matchedText}${textTwo[textTwoIndex++]}` | |
textOneIndex++; | |
} | |
} | |
return matchedText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment