'use strict' ; returns export function findFirst < T > ( array , p ) { let low = 0 ; let high = array . length ; if ( high === 0 ) { return 0 ; } while ( low < high ) { const mid = Math . floor ( ( low + high ) / 2 ) ; if ( p ( array [ mid ] ) ) { high = mid ; } else { low = mid + 1 ; } } return low ; } export function binarySearch < T > ( array , key , comparator ) { let low = 0 ; let high = array . length - 1 ; while ( low <= high ) { const mid = ( ( low + high ) / 2 ) | 0 ; const comp = comparator ( array [ mid ] , key ) ; if ( comp < 0 ) { low = mid + 1 ; } else if ( comp > 0 ) { high = mid - 1 ; } else { return mid ; } } return - ( low + 1 ) ; }