You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if using a return within a while loop, nothing happens. For example, the follow doesn't work when returning the pivot value directly:
function search(numbers, value) {
left =0
right = numbers.length() -1while (left <= right) {
pivot = left + ((right - left) /2).round()
if (numbers[pivot] == target) {
return pivot // this should exit the loop and return the value
}
if (value < numbers[pivot]) {
right = pivot -1
} else {
left = pivot +1
}
}
return-1
}
print(search([1, 2, 3], 2)) // should return 1
The text was updated successfully, but these errors were encountered:
Currently, if using a
return
within awhile
loop, nothing happens. For example, the follow doesn't work when returning thepivot
value directly:The text was updated successfully, but these errors were encountered: