issue #631 solved (#809)

Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
This commit is contained in:
Samay Sagar 2022-01-22 15:05:06 +05:30 committed by GitHub
parent 8c433f9b5d
commit d80486f1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,14 +43,14 @@ export default function knuthMorrisPratt(text, word) {
if (text[textIndex] === word[wordIndex]) {
// We've found a match.
if (wordIndex === word.length - 1) {
return (textIndex - word.length) + 1;
return textIndex - word.length + 1;
}
wordIndex += 1;
textIndex += 1;
} else if (wordIndex > 0) {
wordIndex = patternTable[wordIndex - 1];
} else {
wordIndex = 0;
// wordIndex = 0;
textIndex += 1;
}
}