ran npm run tdd

This commit is contained in:
King
2018-01-17 13:40:40 -05:00
parent f232347f8a
commit 129a6fb333
244 changed files with 894 additions and 371 deletions

View File

@ -1,7 +1,8 @@
module.exports = binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
if (start > end) return -1;
const mid = Math.floor((start + end) / 2);
if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
return mid;
}
}
module.exports = binarySearch