From d80486f1c6a7fcb6b9249f9907c9d2c9ae05c365 Mon Sep 17 00:00:00 2001 From: Samay Sagar <73112080+samay-rgb@users.noreply.github.com> Date: Sat, 22 Jan 2022 15:05:06 +0530 Subject: [PATCH] issue #631 solved (#809) Co-authored-by: Oleksii Trekhleb --- src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js b/src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js index e4344b77..82b94904 100644 --- a/src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js +++ b/src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js @@ -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; } }