Binary and linear search in Javascript

preview_player
Показать описание
Quick tutorial on Binary and Linear search in Javascript. It's raining out. Fairly peaceful. Got that Miles Davis 'round about midnight playing. Not bad.
Рекомендации по теме
Комментарии
Автор

thanks alot man yohh great vid.
i was breathing through the wound before this

mandlankosi
Автор

Thanks for the video helped me a lot! :)

PS: Made another solution for binary search:

/* Returns either the index of the location in the array,
or -1 if the array did not contain the targetValue */


function binarySearch(array, targetValue) {
var min = 0;
var max = array.length - 1;
var guess;
while(min<=max){
guess = Math.floor((min + max)/2);

return guess;
}else if(array[guess]<targetValue){
min = guess+1;
}else{
max = guess -1;
}// end of else
}
return -1;
};

kristofs
Автор

Hey, can you please tell me how would you console.log these returns, like "Found" else, "not found"? I can do it with C but hell, can not able to it with JS without some side effects.

devdude