src/metrics/distance/ratcliff-obershelp.js
function indexOf(haystack, needle) {
  if (typeof haystack === 'string')
    return haystack.indexOf(needle);

  for (let i = 0, j = 0, l = haystack.length, n = needle.length; i < l; i++) {
    if (haystack[i] === needle[j]) {
      j++;

      if (j === n)
        return i - j + 1;
    }
    else {
      j = 0;
    }
  }

  return -1;
}
function indexOf(haystack, needle) {
  if (typeof haystack === 'string')
    return haystack.indexOf(needle);

  for (let i = 0, j = 0, l = haystack.length, n = needle.length; i < l; i++) {
    if (haystack[i] === needle[j]) {
      j++;

      if (j === n)
        return i - j + 1;
    }
    else {
      j = 0;
    }
  }

  return -1;
}
function indexOf ( haystack , needle ) { if ( typeof haystack === 'string' ) return haystack . indexOf ( needle ) ; for ( let i = 0 , j = 0 , l = haystack . length , n = needle . length ; i < l ; i ++ ) { if ( haystack [ i ] === needle [ j ] ) { j ++ ; if ( j === n ) return i - j + 1 ; } else { j = 0 ; } } return - 1 ; }
Abstract indexOf helper needed to find the given subsequence's starting
index in the given sequence. Note that this function may seem naive
because it misses cases when, for instance, the subsequence is not found
but this is of no concern because we use the function in cases when it's
not possible that the subsequence is not found.

@param  {mixed}  haystack - Target sequence.
@param  {mixed}  needle   - Subsequence to find.
@return {number}          - The starting index.
Abstract indexOf helper needed to find the given subsequence s starting index in the given sequence . Note that this function may seem naive because it misses cases when for instance the subsequence is not found but this is of no concern because we use the function in cases when it s not possible that the subsequence is not found .