DEV Community

loading...

Discussion on: The algorithm behind Ctrl + F.

Collapse
kshcode profile image
SeongHoon Kim • Edited

That code does not work for a string which is consisting of only the same character. (e.g. pattern = 'TT')

so, after replacing 'skip = Math.max(1,j-map[string[i+j]]);' with 'skip = Math.max(1,j-map[string[i+j].charCodeAt(0)]);', working correctly.

Collapse
akhilpokle profile image
Akhil Author

Thanks for pointing out :) Code updated!

Collapse
kshcode profile image
SeongHoon Kim

well, the combined code is still the same as before.