lib/algorithms.js
function prefix(p) {

    /* pi contains the computed skip marks */
    var pi = [0],
        k = 0;
    for (q = 1; q < p.length; q++) {
      while (k > 0 && p.charAt(k) !== p.charAt(q)) {
        k = pi[k - 1];
      }if (p.charAt(k) === p.charAt(q)) {
        k++;
      }

      pi[q] = k;
    }
    return pi;
  }
function prefix(p) {

    /* pi contains the computed skip marks */
    var pi = [0],
        k = 0;
    for (q = 1; q < p.length; q++) {
      while (k > 0 && p.charAt(k) !== p.charAt(q)) {
        k = pi[k - 1];
      }if (p.charAt(k) === p.charAt(q)) {
        k++;
      }

      pi[q] = k;
    }
    return pi;
  }
function prefix ( p ) { /* pi contains the computed skip marks */ var pi = [ 0 ] , k = 0 ; for ( q = 1 ; q < p . length ; q ++ ) { while ( k > 0 && p . charAt ( k ) !== p . charAt ( q ) ) { k = pi [ k - 1 ] ; } if ( p . charAt ( k ) === p . charAt ( q ) ) { k ++ ; } pi [ q ] = k ; } return pi ; }
PREFIX, OVERLAP or FALIURE function for KMP. Computes how many iterations
the algorithm can skip after a mismatch.

@input p - pattern (string)
@result array of skippable iterations
PREFIX OVERLAP or FALIURE function for KMP . Computes how many iterations the algorithm can skip after a mismatch .