All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.cesium.binarySearch.kt Maven / Gradle / Ivy

// Automatically generated - do not modify!

@file:JsModule("cesium")

package cesium

/**
 * Finds an item in a sorted array.
 * ```
 * // Create a comparator function to search through an array of numbers.
 * function comparator(a, b) {
 *     return a - b;
 * };
 * const numbers = [0, 2, 4, 6, 8];
 * const index = binarySearch(numbers, 6, comparator); // 3
 * ```
 * @param [array] The sorted array to search.
 * @param [itemToFind] The item to find in the array.
 * @param [comparator] The function to use to compare the item to
 *   elements in the array.
 * @return The index of `itemToFind` in the array, if it exists.  If `itemToFind`
 *   does not exist, the return value is a negative number which is the bitwise complement (~)
 *   of the index before which the itemToFind should be inserted in order to maintain the
 *   sorted order of the array.
 * @see Online Documentation
 */
external fun binarySearch(
    array: Array,
    itemToFind: Any,
    comparator: binarySearchComparator,
): Int




© 2015 - 2024 Weber Informatics LLC | Privacy Policy