vis-util
    Preparing search index...

    Function binarySearchValue

    • This function does a binary search for a specific value in a sorted array. If it does not exist but is in between of two values, we return either the one before or the one after, depending on user input If it is found, we return the index, else -1.

      Type Parameters

      • T extends string

      Parameters

      • orderedItems: { [K in string]: number }[]

        Sorted array.

      • target: number

        The searched value.

      • field: T

        Name of the property in items to be searched.

      • sidePreference: "after" | "before"

        If the target is between two values, should the index of the before or the after be returned?

      • Optionalcomparator: (a: number, b: number) => -1 | 0 | 1

        An optional comparator, returning -1, 0, 1 for <, ===, >.

      Returns number

      The index of found value or -1 if nothing was found.