mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-27 15:41:16 +08:00
Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
This commit is contained in:
parent
8c433f9b5d
commit
d80486f1c6
@ -43,14 +43,14 @@ export default function knuthMorrisPratt(text, word) {
|
|||||||
if (text[textIndex] === word[wordIndex]) {
|
if (text[textIndex] === word[wordIndex]) {
|
||||||
// We've found a match.
|
// We've found a match.
|
||||||
if (wordIndex === word.length - 1) {
|
if (wordIndex === word.length - 1) {
|
||||||
return (textIndex - word.length) + 1;
|
return textIndex - word.length + 1;
|
||||||
}
|
}
|
||||||
wordIndex += 1;
|
wordIndex += 1;
|
||||||
textIndex += 1;
|
textIndex += 1;
|
||||||
} else if (wordIndex > 0) {
|
} else if (wordIndex > 0) {
|
||||||
wordIndex = patternTable[wordIndex - 1];
|
wordIndex = patternTable[wordIndex - 1];
|
||||||
} else {
|
} else {
|
||||||
wordIndex = 0;
|
// wordIndex = 0;
|
||||||
textIndex += 1;
|
textIndex += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user