function indexOf(source, pat, start = 0) {
  if (start >= source.length) {
    return -1;
  }
  if (start < 0) {
    start = 0;
  }
  const s = pat[0];
  for (let i = start; i < source.length; i++) {
    if (source[i] !== s) continue;
    const pin = i;
    let matched = 1;
    let j = i;
    while (matched < pat.length) {
      j++;
      if (source[j] !== pat[j - pin]) {
        break;
      }
      matched++;
    }
    if (matched === pat.length) {
      return pin;
    }
  }
  return -1;
}
/** Find first 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 first 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 first 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 indexOf(source, pat, start = 0) {
  if (start >= source.length) {
    return -1;
  }
  if (start < 0) {
    start = 0;
  }
  const s = pat[0];
  for (let i = start; i < source.length; i++) {
    if (source[i] !== s) continue;
    const pin = i;
    let matched = 1;
    let j = i;
    while (matched < pat.length) {
      j++;
      if (source[j] !== pat[j - pin]) {
        break;
      }
      matched++;
    }
    if (matched === pat.length) {
      return pin;
    }
  }
  return -1;
}
function indexOf ( source , pat , start = 0 ) { if ( start >= source . length ) { return - 1 ; } if ( start < 0 ) { start = 0 ; } const s = pat [ 0 ] ; for ( let i = start ; i < source . length ; i ++ ) { if ( source [ i ] !== s ) continue ; const pin = i ; let matched = 1 ; let j = i ; while ( matched < pat . length ) { j ++ ; if ( source [ j ] !== pat [ j - pin ] ) { break ; } matched ++ ; } if ( matched === pat . length ) { return pin ; } } return - 1 ; }
Find first index of binary pattern from source.
Find first index of binary pattern from source .