(arr, value, lt, gt, i, j)
| 335 | } |
| 336 | |
| 337 | function binarySearch(arr, value, lt, gt, i, j) { |
| 338 | if (Math.abs(j - i) <= 1) { |
| 339 | return (i + j)/2; |
| 340 | } |
| 341 | |
| 342 | var m = Math.floor((i + j)/2) |
| 343 | var cmpVal = arr[m]; |
| 344 | if (gt(cmpVal, value)) { |
| 345 | j = m; |
| 346 | } else if (lt(cmpVal, value)){ |
| 347 | i = m; |
| 348 | } else { |
| 349 | return m; |
| 350 | } |
| 351 | return binarySearch(arr, value, lt, gt, i, j); |
| 352 | } |
| 353 | |
| 354 | init(); |
no test coverage detected