xamples
epeat
ode
pproach
ptimize
est
Implement the indexOf method for strings.
The indexOf method takes a “haystack” string, and a “needle” string to search for.
So, indexOf(“hello world”, “or”) would return 7.
https://repl.it/EOW4
A slightly less verbose implementation:
https://repl.it/EOWZ
There are some really interesting algorithms that do this in O(m + k) time (the Knuth–Morris–Pratt Algorithm). Watch this video for more information
https://www.youtube.com/watch?v=GTJr8OvyEVQ