searching/knuth-morris-pratt

Knuth–Morris–Pratt algorithm. Searches for the position of the first occurrence of a specified value in a string.
Source:
Parameters:
Name Type Description
str String String.
substr String Substring.
Returns:
Type:
Number
A Number, representing the position where the specified substring occurs for the first time, or -1 if it never occurs.
Example
var indexOf = require('path-to-algorithm/src/searching/'+
'knuth-morris-pratt').kmp;
console.log(indexOf('hello', 'll')); // 2