Z Algorithm for pattern matching


var text = "aabcaabxaaaz";

// Accepts the text and the pattern to be searched as parameters
console.log(zSearch(text, "ab"));
// Returns an array of all the indices where the pattern was found