Skip to main content

Data Structures and Algorithms: Binary Search

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 catalog. Scrimba's catalog data lists it under the Frontend Developer Path and the Fullstack Developer Path.

Quick answer​

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 course first for breadth, or come here for depth once you have it.

Is it worth your time?​

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.

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 course is the closest thing to the follow-up.

What you'll learn​

Course curriculum

12 scrims, no modules; grouping below is mine

  1. The idea: big O and the splitting strategy15 min2 lessons
  2. Six implementations, each a challenge43 min6 lessons
  3. Wrap up, certificate, and Scrimba clips6 min4 lessons

Scrimba presents the course as one flat list of 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.

Inside the course, lesson by lesson​

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.
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.
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 [email protected] 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.
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.
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.
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.

What a lesson feels like​

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 the full transcript panel are there, and playback speed is adjustable. 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.

Free or Pro: exactly what is gated​

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 Scrimba lists this course under and the Pro-only channels on Scrimba's Discord; the pricing page lists basic Discord access as free. See current plans (opens in a new tab) for what Pro costs in your region.

How long it takes​

Sixty three minutes of video, but six of the scrims 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.

Who it's for, and who should skip it​

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 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 (opens in a new tab)

Prerequisites​

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.

Where it fits​

Scrimba's catalog data lists the course under the Frontend Developer Path and the Fullstack Developer Path. It pairs with the same instructor's Merge Sort course, which uses the same challenge-then-solution format on a sorting algorithm. Take the broad Data Structures and Algorithms course first if you want the vocabulary, and JavaScript Interview Challenges afterwards if the goal is interviews.

Strengths and limits​

What it does well: every implementation is a real challenge with a test suite, the bugs happen on screen and get read out loud, 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, and the three free scrims are enough to judge the format.

Where it is limited: it is one algorithm in one hour, so the title promises more than it delivers. The code comments and the narration in the implementation lessons describe the loop and recursive versions as 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 intro and wrap-up still talk about the course as a free preview of a bigger course "coming out later this year," which dates it. And the last three scrims are Scrimba marketing, not teaching.