小于 1 分钟
Home > @hz-9/algorithm > binarySearch
binarySearch() function
Binary search algorithm. Input parameters must be sorted in ascending order.
二分搜索算法。 传入参数无需排序。
Signature:
binarySearch: <T>(array: T[], target: T, compareFn?: CompareFn<T>) => numberParameters
Parameter | Type | Description |
|---|---|---|
array | T[] | |
target | T | |
compareFn | CompareFn<T> | (Optional) The compare function. |
Returns:
number
- The index of the value in the list. If the value is not found, return -1.