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:
Alexandr Shulaev
2022-11-19 00:46:18 +04:00
committed by GitHub
parent 64a09d6584
commit 5f416d1129
3 changed files with 39 additions and 30 deletions

View File

@@ -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;
}