Options
All
  • Public
  • Public/Protected
  • All
Menu

Module algorithm

Index

Functions

binarySearch

  • binarySearch(array: number[], value: number): number
  • Searches the sorted number array for an element and returns the index of that element.

    Parameters

    • array: number[]

      The array to search in.

    • value: number

      The value to search.

    Returns number

    The index of the searched element in the sorted array, if one is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is large than the searched value or, if there is no larger element(include the case that the array is empty), the bitwise complement of array's length.

binarySearchBy

  • binarySearchBy<T>(array: T[], value: T, lessThan: (lhs: T, rhs: T) => boolean): number
  • Searches the sorted array for an element and returns the index of that element.

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to search in.

    • value: T

      The value to search.

    • lessThan: (lhs: T, rhs: T) => boolean

      The predicate which implements the less than semantic.

        • (lhs: T, rhs: T): boolean
        • Parameters

          • lhs: T
          • rhs: T

          Returns boolean

    Returns number

    The index of the searched element in the sorted array, if one is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is large than the searched value or, if there is no larger element(include the case that the array is empty), the bitwise complement of array's length.

binarySearchEpsilon

  • binarySearchEpsilon(array: number[], value: number, EPSILON?: number): number
  • Searches the sorted number array for an element and returns the index of that element.

    Parameters

    • array: number[]

      The array to search in.

    • value: number

      The value to search.

    • Default value EPSILON: number = 0.000001

      The epsilon to compare the numbers. Default to 1e-6.

    Returns number

    The index of the searched element in the sorted array, if one is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is large than the searched value or, if there is no larger element(include the case that the array is empty), the bitwise complement of array's length.

Generated using TypeDoc