-
Notifications
You must be signed in to change notification settings - Fork 1
array_binary_search
Hyomoto edited this page Jun 13, 2021
·
2 revisions
Jump To | Go Back |
Arguments |
---|
Returns: [mixed
or ValueNotFound](mixed
or ValueNotFound)
Throws: InvalidArgumentType
Uses a binary search on the given array to find the position of value. The array must be sorted for binary search to work, otherwise results will be inconsistent. You can override the function used for comparison by specifying func. If the value is not found, ValueNotFound will be returned. If an array is not provided to search, or a method is not provided for func InvalidArgumentType will be thrown.
array_binary_search( [ 10, 20, 30, 40, 50 ], 40 );
Output: 3
Name | Type | Purpose |
---|---|---|
array | [Array](array) |
The array to search |
value | [Mixed](mixed) |
The value to find |
*func | method |
optional: If provided, will be used for sake of comparison |
Devon Mullane 2020