Now we have to come up with a guess.
Can't believe I missed that. Since that is not the case, we will now discard half of the array. Because our guess was too low, we discard the bottom half of the array by increasing the min , conversely to what we previously did to max:.
I have it set to print out the numbers so I can can input a number I'm sure is in the array, but when I put in a number that I see is there, it almost always returns false. It never occurred to me to print it out as the function was operating. Related 2851. I did have it printing out the contents of the array beforehand. I have it set to print out numbers like this: Never miss a story from freeCodeCamp.
Thank you so much.
Since our original guess of 14 was greater than 7, we now decrease it by 1 and store that into max:. The smartest thing to do would be to guess an index value in the middle of the array.
And we are left with only one value, 4, as the index of the target number we were looking for, which was 7. The purpose of binary search is to get rid of half of the array at every iteration.
If this question can be reworded to fit the rules in the help center , please edit the question. There are 17 items in total and the index values go from 0 to 16. After the first iteration, our search is now within: