Issues-126 - Fixed formatting, jsdoc and example for JavaScript/ES6 (#127)
* Issues-126 - Fixed formatting, jsdoc and non-working example for JavaScript/ES6 * Issues-126 - Fixed jsdoc
This commit is contained in:
@@ -1,22 +1,28 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Searches recursively number from the list
|
||||
* @param {Array} list Source array
|
||||
* @param {number} item Search item
|
||||
* @returns {(number|null)} Number if the value is found or NULL otherwise
|
||||
*/
|
||||
function binary_search(list, item) {
|
||||
let low = 0;
|
||||
let high = list.length - 1;
|
||||
|
||||
|
||||
while (low <= high) {
|
||||
let mid = Math.floor((low + high) / 2);
|
||||
let guess = list[mid];
|
||||
if (guess === item) {
|
||||
const mid = Math.floor((low + high) / 2);
|
||||
const guess = list[mid];
|
||||
|
||||
if (guess === item) {
|
||||
return mid;
|
||||
}
|
||||
if (guess > item) {
|
||||
} else if (guess > item) {
|
||||
high = mid - 1;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user