Knut Morris Pratt algroithm's realisation in js