Function insort

  • Runs bisect first to locate an insertion point, and inserts the value x in the sorted array after any existing entries of x to maintain sort order. Please note this method is O(n) because insertion resizes the array.

    Returns

    Type Parameters

    • T

    Parameters

    • arr: T[]

      The array to insert into

    • x: any

      The element to insert

    • lo: number = 0

      The starting index

    • Optional hi: any

      The end index to search within

    • comp: ((x: any, y: any) => number) = compare

      The compare function to check for x

        • (x: any, y: any): number
        • Checks whether x is a comparable type and returns the result of x.compare(y). Otherwise the return value of the compare function is equivalent to obj === other ? 0 : obj < other ? -1 : 1

          Returns

          The comparison result

          See

          Parameters

          • x: any

            An initial value

          • y: any

            Other value to compare

          Returns number

    Returns T[]

Generated using TypeDoc