function findIndex(source, pat) {
  const s = pat[0];
  for (let i = 0; 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 a. If not found, then return -1
 * @param source source array
 * @param pat pattern to find in source array
 */
Find first index of binary pattern from a. If not found, then return -1
@param source source array
@param pat pattern to find in source array
Find first index of binary pattern from a . If not found then return - 1 @param source source array @param pat pattern to find in source array
function findIndex(source, pat) {
  const s = pat[0];
  for (let i = 0; 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 findIndex ( source , pat ) { const s = pat [ 0 ] ; for ( let i = 0 ; 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 a.
Find first index of binary pattern from a .