Searchs for specific element in a given array using
the binary search algorithm.
Time complexity: O(log N).
Time complexity: O(log N).
Parameters:
| Name | Type | Description |
|---|---|---|
array |
Array | Input array. |
value |
Number | Value of the element which index should be found. |
- Source:
Returns:
Index of the element or -1 if not found.
- Type
- Number
Example
var search = require('path-to-algorithms/src/searching/'+
'binarysearch').binarySearch;
console.log(search([1, 2, 3, 4, 5], 4)); // 3