Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function firstBadVersion(arr){
let found = undefined, start = 0, end = arr.length;
while (start < end && !found){
let mid = Math.floor((start + end)/2);
if (isBad(arr[mid])){
if (arr[mid - 1] && isBad(arr[mid - 1])){
end = mid - 1;
}
else{
found = mid;
}
}
else{
start = mid + 1;
}
}
return found;
}
function isBad(version){
return version === 'B';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment