knuthMorrisPratt = (text, pattern) => {
  const textLength = text.length;
  const patternLength = pattern.length;
  let m = 0;
  let i = 0;
  const table = buildTable(pattern);

  while (m + i < textLength) {
    if (pattern[i] === text[m + i]) {
      if (i === patternLength - 1) {
        return m;
      }
      i++;
    } else if (table[i] >= 0) {
      i = table[i];
      m = m + i - table[i];
    } else {
      i = 0;
      m++;
    }
  }

  return textLength;
}
String Matching algorithm
Tries to match the given pattern inside the given text
If the pattern exists inside the text, it will be returned
the index of the begining of the pattern in the text,
otherwise it will be returned the length of the text

Asymptotic Complexity: O(text.length)

@param {Array} text of Numbers, Strings or Characters
    or {String}
@param {Array} pattern of Numbers, Strings or Characters
    or {String}
@return {Number}