function lastIndexOf(source, pat, start = source.length - 1) {
  if (start < 0) {
    return -1;
  }
  if (start >= source.length) {
    start = source.length - 1;
  }
  const e = pat[pat.length - 1];
  for (let i = start; i >= 0; i--) {
    if (source[i] !== e) continue;
    const pin = i;
    let matched = 1;
    let j = i;
    while (matched < pat.length) {
      j--;
      if (source[j] !== pat[pat.length - 1 - (pin - j)]) {
        break;
      }
      matched++;
    }
    if (matched === pat.length) {
      return pin - pat.length + 1;
    }
  }
  return -1;
}
/** Find last index of binary pattern from source. If not found, then return -1.
 * @param source source array
 * @param pat pattern to find in source array
 * @param start the index to start looking in the source
 */
Find last index of binary pattern from source. If not found, then return -1.
@param source source array
@param pat pattern to find in source array
@param start the index to start looking in the source
Find last index of binary pattern from source . If not found then return - 1 . @param source source array @param pat pattern to find in source array @param start the index to start looking in the source
function lastIndexOf(source, pat, start = source.length - 1) {
  if (start < 0) {
    return -1;
  }
  if (start >= source.length) {
    start = source.length - 1;
  }
  const e = pat[pat.length - 1];
  for (let i = start; i >= 0; i--) {
    if (source[i] !== e) continue;
    const pin = i;
    let matched = 1;
    let j = i;
    while (matched < pat.length) {
      j--;
      if (source[j] !== pat[pat.length - 1 - (pin - j)]) {
        break;
      }
      matched++;
    }
    if (matched === pat.length) {
      return pin - pat.length + 1;
    }
  }
  return -1;
}
function lastIndexOf ( source , pat , start = source . length - 1 ) { if ( start < 0 ) { return - 1 ; } if ( start >= source . length ) { start = source . length - 1 ; } const e = pat [ pat . length - 1 ] ; for ( let i = start ; i >= 0 ; i -- ) { if ( source [ i ] !== e ) continue ; const pin = i ; let matched = 1 ; let j = i ; while ( matched < pat . length ) { j -- ; if ( source [ j ] !== pat [ pat . length - 1 - ( pin - j ) ] ) { break ; } matched ++ ; } if ( matched === pat . length ) { return pin - pat . length + 1 ; } } return - 1 ; }
Find last index of binary pattern from source.
Find last index of binary pattern from source .