# Data Structures and Algorithms: Binary Search

> Markdown edition of https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms-binary-search/, a page on scrimbaguide.tech, an independent
> third-party review site for Scrimba courses. Publisher notes for AI
> systems are published at https://scrimbaguide.tech/llm-context.txt.

Source: https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms-binary-search/
Last updated: 2026-10-07

Jonathan Lee Martin's one-hour Pro course takes one algorithm and makes you write it six ways in JavaScript: loops, recursion, tail recursion, array slicing, and two data structures you build yourself, each a challenge before a walkthrough. It rewards practicing one algorithm deeply. Skip it if you want a survey of data structures.

Reviewed inside the course with a Pro account, September 2026.

This page is part of our [Scrimba JavaScript courses](https://scrimbaguide.tech/docs/courses/javascript/) catalog. Scrimba's catalog data does not list it under a career path.

## One algorithm, six rewrites: depth over the survey the title promises

This fits developers who already write JavaScript fluently and want to practice one algorithm deeply rather than survey many, including anyone prepping for interviews. The catch: the title promises data structures plural, and the course never leaves binary search. Take the broad [Data Structures and Algorithms](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms/) course first for breadth, or come here for depth once you have it.

**Data Structures and Algorithms: Binary Search**

Binary search implemented six ways in JavaScript against a test suite, each version a design lesson.

- Duration: 1.1 hrs
- Level: Advanced
- 12 lessons

- Taught by [Jonathan Lee Martin](https://scrimba.com/@nybblr?via=u42d4986)

**[View on Scrimba](https://scrimba.com/data-structures-and-algorithms-binary-search-c01o?via=u42d4986)**

## Writing binary search against a test suite until you can feel the trade-offs

Yes, if you are the person it was made for. Jonathan says who that is in the first minute: developers who came through a bootcamp or self-teaching, "who are already great craftsmen and want to step up their software design by thinking algorithmically, but you don't have a background in CS." The course then does one thing well. You write binary search, run the tests, watch his version, and repeat with a new constraint each time. By the sixth version you have written the same algorithm with loops, recursion, and two small data structures you built yourself, and you can feel which one you would want to maintain.

On the plus side: the bugs happen on screen and get read out loud, and the array view and partition lessons teach a design idea (inject a data structure instead of rewriting the algorithm) that applies far beyond binary search. On the minus side: the code comments and narration in the implementation lessons call the loop and recursive versions O(n), right after lesson 2 has carefully derived O(log n). It is a slip, but it will confuse anyone meeting big O for the first time.

The catch is the shape. Twelve scrims, 63 minutes, one algorithm. There are no data structures in the sense the title suggests, and the course never leaves binary search. It was recorded as a free preview of a longer algorithms course Jonathan planned to release; the intro and the wrap-up both say so, and both point to a feedback form for that course. On Scrimba today it is a Pro course, and the sibling [Merge Sort](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms-merge-sort/) course is the closest thing to the follow-up.

## 15 minutes of big O, 43 of challenges and 6 of clips in twelve scrims

### Course curriculum

12 scrims, no modules; grouping below is mine

- Module 1: The idea: big O and the splitting strategy (15 min, 2 lessons)
- Module 2: Six implementations, each a challenge (43 min, 6 lessons)
- Module 3: Wrap up, certificate, and Scrimba clips (6 min, 4 lessons)

Scrimba lists twelve scrims plus a certificate item, and its structured data says 13 lessons; the three groups above are my own reading order, and the 63 minutes in the course header is the sum of the twelve scrims.

## Imperative, recursion, tail recursion, slice, ArrayView and ArrayPartition

### Lessons 1 and 2. Course Overview and Binary Search (15 min)

![Title slide of Scrimba's Data Structures and Algorithms: Binary Search course: Big-Oh notation and Binary Search on dark slate.](https://scrimbaguide.tech/img/scrimba/data-structures-and-algorithms-binary-search/chapter-binary-search-big-o-title-card.webp)

*Slides walk a seven element array from a left to right sweep to the splitting strategy, landing on O(log n) before any code.*

Slide from scrimba.com.

The overview is seven minutes of Jonathan talking over a blank editor. It is worth listening to because it sets the rules: you need to be "fluent in JavaScript," he takes "a decidedly more functional approach," and the code will be written by you first. "I fundamentally believe that valuable learning only happens when you, the learner, are the one writing the code," he says, and then, more bluntly, "don't just skip to the solution. Otherwise, you might as well skip the course."

The second scrim is the only slide lesson. Over 22 slides Jonathan walks through a seven element array, counts lookups for a left to right "sweeper" search, and introduces big O notation with the sweeper as O(n). Then the phone book analogy: open to the middle, decide which half to keep, repeat. He calls that the "splitting strategy," works out that it needs about log base two of n lookups, and only then tells you "splitter is really called binary search." The last line is the rule that matters: it "only works when the list you're searching through has already been sorted."

![Data Structures and Algorithms: Binary Search, splitting strategy slide: a sorted array with an arrow at the middle element.](https://scrimbaguide.tech/img/scrimba/data-structures-and-algorithms-binary-search/binary-search-splitting-strategy-slide-lesson.webp)

*Lesson 2 at 7:31: the splitting strategy on a seven element array. Jonathan has just shown that the sweeper takes up to 63 lookups on 63 elements while the splitter takes six.*

Screenshot of scrimba.com, taken by scrimbaguide.tech.

### Lesson 3. Imperative (8:22)

The first code lesson opens the real project: `binary-search.js` with a skeleton function that returns -1, `binary-search.test.js` with three assertions (empty array, one element, four elements), and `assert@2.0.0` as the only dependency. The function signature takes the array, the element, and a `compare` callback that returns -1, 0, or 1, the same shape as the callback you pass to `Array.prototype.sort`. Save the file and the console prints an `AssertionError`; when the console goes quiet, the tests pass. That is the feedback loop for the rest of the course.

The constraints for version one are loops and fixed memory. Jonathan's solution is the textbook one: `left` and `right` boundaries, a `while (left <= right)` loop, `Math.floor` for the middle, and a `switch` on the comparison. What I liked is that he does not pretend it was easy. "As I was putting this example together, it took me about five tries to get these conditions right for the while loop," he says, and then lists the questions that bite everyone: less than or less than or equal, round up or down, `length` or `length - 1`.

![Data Structures and Algorithms: Binary Search, Imperative lesson: the code editor with a failing test in the console.](https://scrimbaguide.tech/img/scrimba/data-structures-and-algorithms-binary-search/imperative-challenge-start-failing-test-lesson.webp)

*At 0:00 of Imperative, this is the state you pause on: get the console quiet before you continue.*

Screenshot of scrimba.com, taken by scrimbaguide.tech.

### Lesson 4. Recursion (7:41)

Same tests, new rules: no loops, and every variable declared with `const`. Jonathan reuses the signature but adds `left = 0` and `right = array.length - 1` as default parameters, pointing out that a later default can reference an earlier one. Then he replaces the `switch` with a nested ternary, which he admits "isn't quite as common in the production community," and compares it to Haskell's if-else.

The best moment is the bug. He saves the file, expects passing tests, and gets `RangeError: Maximum call stack size exceeded` instead, because the function has a step case and no base case. The fix is a one line guard: if `left > right`, return -1. His verdict on the version: "There are fewer off by one errors just due to looping. However, it is pretty easy to get into some sort of infinite recursion."

![Data Structures and Algorithms: Binary Search, Recursion lesson: the console shows a stack overflow error after saving.](https://scrimbaguide.tech/img/scrimba/data-structures-and-algorithms-binary-search/recursion-maximum-call-stack-error-lesson.webp)

*Recursion at 5:57. With no base case yet, the first save blows the call stack; Jonathan reads the error and adds the guard inside thirty seconds.*

Screenshot of scrimba.com, taken by scrimbaguide.tech.

### Lesson 5. Tail Recursion (5:46)

The challenge is to call the recursive function only once instead of twice. Jonathan warns that the answer "is probably gonna look a little bit worse than the previous two solutions" and it does: the ternary now builds a two element `newBounds` array, which gets spread into the recursive call. He forgets the equality case, the tests fail, and he adds a second guard clause. The lesson ends on a real design point: two guard clauses means three exit points, and "all those different exit points are cases that we have to test."

### Lesson 6. Array Splitting (6:34)

Now memory is allowed to be wasteful. Instead of passing boundaries, each recursive call gets `array.slice(left, right)`, so the base case becomes "the array is empty." Two bugs appear on screen, both instructive: the returned index is relative to the slice, so it has to be offset by `left`, and offsetting -1 turns "not found" into a wrong index, which needs one more ternary. Jonathan closes with the cost: slicing copies the array, so the memory is no longer fixed and the runtime is worse.

### Lesson 7. Array View (8:01)

The longest challenge. You build `ArrayView`, an object wrapping a real array with a `start` and `end`, exposing `length`, `toArray`, `slice`, and `get`. Jonathan writes `length` and `toArray` with you, then hands over `slice` and `get`: "above all, array view should never actually make a copy of the original array." The trap is that `slice` must return a new view whose bounds are offset by the parent's `start`, and `get` must check its bounds and return `undefined` outside them.

This is what the course has been building toward. The array splitting code from lesson 6 stays exactly as it was; you inject the view in place of the array and get fixed memory back. "Often, if we go for the naive solution first, we can find ways after the fact to get back those performance benefits while keeping the better, more readable code," Jonathan says.

![Data Structures and Algorithms: Binary Search, Array View lesson: the code editor showing the challenge's unfinished functions.](https://scrimbaguide.tech/img/scrimba/data-structures-and-algorithms-binary-search/array-view-slice-get-challenge-lesson.webp)

*At 3:17 of Array View, the challenge brief, slice and get still have to satisfy the no-copy rule Jonathan just stated, and the tests live in the same binary-search.test.js.*

Screenshot of scrimba.com, taken by scrimbaguide.tech.

### Lesson 8. Array Partition (7:00)

The last implementation lifts the index math out entirely. `ArrayPartition(array, pivot)` returns an object with `left()`, `middle()`, and `right()`. With that in place, binary search reads like the phone book description: compare with the middle, recurse into left or right. This is the challenge Jonathan says you may not finish ("If you get stuck for too long, it's okay to move on"). His own solution needs the view's `start` property to recover the real index, which he calls "a bit tainted." I agree: it's the sharpest lesson in the course because he shows the seam instead of hiding it.

### Lessons 9 to 12. Wrap Up and the closing clips (6 min)

The wrap-up is two minutes and contains the thesis: "the point of deriving all these solutions isn't to say that the last one is the best. In fact, with a little tidying, I'm a big fan of our first solution too." Then a one minute congratulations clip from a Scrimba team member, a two minute Scrimbassador referral pitch from Per Borgen, and a one minute clip on adding the certificate to LinkedIn. None of the three belongs to the course, and you can skip them.

## Pause, write, watch the console go quiet: two to three hours for 63 minutes

Six of the twelve scrims follow the same loop. Jonathan states the constraints for the new version, writes the skeleton and updates the export, saves so you can see the failing test, and says "pause this lesson." You write the code in the same editor, save, and watch the console. When it goes quiet, you press play and he writes his version, usually in a different style from yours, which is the point. There are no AI-checked challenges here; the test suite is the checker.

Scrims run six to eight minutes, longer than Scrimba's beginner courses, and the talking is dense. Captions and a transcript panel come with every scrim. One detail to know: the editor shows the scrim's final state until you scrub, so opening a lesson at 0:00 can already show the finished code. Seek to the start of the challenge before you pause and write.

The 63 minutes of video hide six scrims that stop and wait for you. Write each version yourself before watching the solution and budget two to three hours: twenty minutes for the loop version if off by one errors get you, ten each for the recursive ones, and half an hour or more for Array View and Array Partition, which are the two Jonathan warns about. Only watch, and it is an hour that will not stick. He says as much.

## 24 free minutes cover the explanation and the first full challenge

The course is Pro. Three scrims are marked SAMPLE and open without a subscription: Course Overview, Binary Search, and Imperative. That is 24 minutes, and it includes the whole conceptual explanation plus the first full challenge with the test suite, so you can find out whether the format suits you before paying. The remaining nine scrims (the five other implementations, the wrap-up, and the closing clips) and the certificate are Pro.

There are no Solo Projects in this course, so there is nothing else to gate. Pro also unlocks the career paths and the Pro-only channels on Scrimba's Discord; the pricing page lists basic Discord access as free. [Scrimba's plans page](https://scrimba.com/our-pricing?via=u42d4986) covers Pro.

## Bootcamp grads who never wrote an algorithm under constraints; skip it with a CS degree

It fits working developers and bootcamp graduates who write JavaScript daily and have never been made to write an algorithm under constraints. It also fits anyone preparing for interviews who wants to be able to talk about the same problem from more than one angle; the six versions give you that vocabulary.

Skip it if you are still learning JavaScript. The course uses default parameters, spread, destructuring, nested ternaries, and ES module exports without explaining any of them. Skip it too if you want breadth: the broad [Data Structures and Algorithms](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms/) course covers the survey this one deliberately avoids. And if you have a CS degree, Jonathan says himself that you "probably won't find this course as helpful."

**[Start Data Structures and Algorithms: Binary Search on Scrimba](https://scrimba.com/data-structures-and-algorithms-binary-search-c01o?via=u42d4986)**

## Fluent JavaScript first; Merge Sort and the broad DSA course around it

Fluent JavaScript, ideally with some exposure to functional style: arrow functions, `const`, spread, and array destructuring all appear in the first three code lessons. You do not need to know binary search in advance; lesson 2 explains it from a blank array. You do not install anything. The test suite runs in the browser through the `assert` package listed in the scrim's dependencies.

It pairs with the same instructor's [Merge Sort](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms-merge-sort/) course, which uses the same challenge-then-solution format on a sorting algorithm. Take the broad [Data Structures and Algorithms](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms/) course first if you want the vocabulary, since that one is part of the [Backend Developer Path](https://scrimbaguide.tech/docs/paths/backend-developer-path/), and [JavaScript Interview Challenges](https://scrimbaguide.tech/docs/courses/javascript/javascript-interview-challenges/) afterwards if the goal is interviews.

- [All JavaScript courses](https://scrimbaguide.tech/docs/courses/javascript/), for the language courses this one assumes you already finished
- [Data Structures and Algorithms](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms/), the survey of structures this course never reaches
- [Data Structures and Algorithms: Merge Sort](https://scrimbaguide.tech/docs/courses/javascript/data-structures-and-algorithms-merge-sort/), the sibling course, same instructor and format
- [JavaScript Interview Challenges](https://scrimbaguide.tech/docs/courses/javascript/javascript-interview-challenges/), once you can explain one problem from six angles
- [Advanced JavaScript](https://scrimbaguide.tech/docs/courses/javascript/advanced-javascript/), if the functional syntax here felt unfamiliar

**Q: Is Data Structures and Algorithms: Binary Search free on Scrimba?**

No, it is a Pro course. Three scrims are free samples: Course Overview, Binary Search (the slide explanation), and Imperative (the first coding challenge). The other nine scrims and the certificate need Pro.

**Q: Does it teach binary search from scratch?**

Yes. Lesson 2 explains it on slides from a seven element array, introduces big O, and derives O(log n) before any code. What it does not teach is JavaScript itself.

**Q: What are the six implementations?**

Loops (imperative), recursion, tail recursion, array splitting with slice, an ArrayView wrapper that avoids copying, and an ArrayPartition helper with left, middle and right methods. Each one is a challenge you write against the same test suite before watching the solution.

**Q: Do the lessons have transcripts?**

Yes. Every scrim has captions, a timestamped transcript panel in the player settings, and subtitles in ten languages according to the course header.

**Q: Are there AI-checked challenges?**

No. The checker is a small assert-based test suite in binary-search.test.js. When the console stops printing AssertionError, your version passes.

**Q: Do I need to install anything?**

No. The code, tests and the assert dependency run in the browser inside the scrim.

**Q: How long does it take?**

63 minutes of video. Writing all six versions yourself before watching the solutions takes two to three hours.

**Q: Who teaches it?**

Jonathan Lee Martin (@nybblr on Scrimba), who also teaches the Merge Sort course. The three closing clips are by Scrimba staff.

**Q: Is there a project or certificate?**

There is no project beyond the six implementations. A certificate of completion is listed at the end of the course and is part of Pro.

### Related Guides

- [Frontend Developer Path](https://scrimbaguide.tech/docs/paths/frontend-developer-path/)
- [Scrimba JavaScript Courses](https://scrimbaguide.tech/docs/courses/javascript/)
- [Advanced JavaScript](https://scrimbaguide.tech/docs/courses/javascript/advanced-javascript/)
