There is a bug in ch03/3.4/src/failure-function.js
vskyman opened this issue · comments
Thanks for your sharing!
Look at the corner case:
input the string: "a a a b"
output "0 1 2 1"
should be "0 1 2 0"
----original------
if(str[j] == str[i]){
j++
}
failure[i] = j
-----change to-------
if(str[j] == str[i]){
j++
failure[i] = j
} else {
failure[i] = 0
}
Your codes are right.