Skip to content

Commit c23ca90

Browse files
VoloshchenkoAlegonSchiele
authored andcommitted
update binarySearch function for es6 recursive (egonSchiele#101)
1 parent c745f5d commit c23ca90

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

01_introduction_to_algorithms/ES6/02_recursive_binary_search.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param {number} high Highest limit of search in the list
77
* @return {(number | null)} Number if the value is found or NULL otherwise
88
*/
9-
const binarySearch = ( list, item, low, high ) => {
9+
const binarySearch = ( list, item, low = 0, high = list.length - 1 ) => {
1010
let arrLength = list.length;
1111
while ( low <= high ) {
1212
let mid = Math.floor((low + high) / 2);
@@ -36,8 +36,6 @@ const binarySearch = ( list, item, low, high ) => {
3636
const createArr = ( n ) => Array.from({length: n}, (v, k) => k + 1);
3737

3838
const myList = createArr( 100 );
39-
let low = 0;
40-
let high = myList.length - 1;
4139

42-
console.log( binarySearch( myList, 3, low, high ) ); // 2
43-
console.log( binarySearch( myList, -1, low, high ) ); // null
40+
console.log( binarySearch( myList, 3 ) ); // 2
41+
console.log( binarySearch( myList, -1 ) ); // null

0 commit comments

Comments
 (0)