Skip to content
dreamcode
dreamcode
Lesson
Practice · Binary search
  1. Predict
  2. Arrange
  3. Fill in
+20 XP on finish
PREDICT · READ BEFORE YOU WRITE

What does this program print?

Trace the program the way the computer would, then make your call before running anything.

const items = [2, 4, 6, 8, 10, 12, 14];
const low = 0;
const high = items.length - 1;
const mid = Math.floor((low + high) / 2);
console.log(mid, items[mid]);