-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BinarySearch #1
Labels
Comments
function BinarySearch(input, key) {
return indexOf(input, key);
function indexOf(a, k) {
var start = 0;
var end = a.length - 1;
while(start <= end) {
var mid = Math.floor((end - start) / 2) + start;
if(k < a[mid]) {
end = mid - 1;
} else if(k > a[mid]) {
start = mid + 1;
} else {
return mid;
}
}
return -1;
}
} |
小胡子哥习惯在函数声明最后面加个封号么? |
@hanzichi 分号去掉了,不是习惯,可能是复制的时候多写了一个。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/chapter-1-fundamentals/1.1-programming-model/BinarySearch.js
The text was updated successfully, but these errors were encountered: