Home My space log
Language EN (English)

Binary search

JavaScript Advanced astronaut ages teen+

The problem

Write a function binarySearch(sorted, target). The list is sorted from smallest to biggest. Give back the position (index) of target, or -1 if it is not there. Do it by halving the part you search each time.

You will practice: binary search, divide and conquer, while loops, indexes

Mode

Press Tab to indent. Press Esc and then Tab to move on to the next button.

Your code runs in your browser. We do not receive it or save it.

Test results

      What your code printed