Refactor Rabin Karp and make it behave like String.prototype.indexOf