Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Solving the Duplication Crisis

You have inherited a Node.js customer-data pipeline that runs fine on a few hundred records but freezes the server on the production-volume 100,000-row dataset. Every slow function shares the same shape — a `filter` callback that calls `Array.includes` or `Array.indexOf` on a second array, turning each pass into an O(n²) scan. In this lab you'll refactor the offending code to use `Set` and `Map`, so each membership check becomes O(1) on average and the same machine can serve production traffic without freezing.

Lab platform
Lab Info
Level
Intermediate
Last updated
May 12, 2026
Duration
30m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
Table of Contents
  1. Challenge

    Step 1: Getting started

    You have inherited a Node.js customer-data pipeline that runs fine on a few hundred records but freezes the server on the production-volume 100,000-row dataset.

    Every slow function shares the same shape: a filter callback that calls Array.includes or Array.indexOf on a second array, turning each pass into an O(n²) scan.

    In this lab you'll refactor the offending code to use Set and Map, so each membership check becomes O(1) on average and the same machine can serve production traffic without freezing. ### Check the baseline performance

    Before changing any code, run the test suite once so you can see the baseline behavior.

    In the terminal, make sure you’re in the application directory, then run:

    ./runTest.sh
    

    The small-fixture correctness checks pass, but every production-volume check fails its performance budget.

    Over the next three steps you'll make each production-volume check pass by reaching for Set and Map in the six source files under src/. > Stuck on a task? Peek at the matching solution/stepN/ folder for the step you're on to see a working implementation. Try the refactor yourself first; the solution is there as a safety net. info> This lab experience was developed by the Pluralsight team using Forge, an internally developed AI tool utilizing Gemini technology. All sections were verified by human experts for accuracy prior to publication. For issue reporting, please contact us.

  2. Challenge

    Step 2: Replace membership checks with a Set

    The blocklist filter is the most direct example of the performance bug. Array.includes walks the blocklist from the start every time it is called, so filtering 100,000 customers against a 10,000-id blocklist can cost up to one billion comparisons.

    Building a Set once turns every subsequent lookup into O(1) average time, while the rest of the function shape stays the same.

  3. Challenge

    Step 3: Deduplicate primitives with a Set

    When you need to deduplicate primitive values, such as strings, numbers, and booleans, a Set is the right tool.

    Built-in equality means you don’t need to write a custom key function, and a single pass is enough: check whether each value has been seen, and if it hasn’t, add it.

  4. Challenge

    Step 4: Deduplicate objects with a Map and intersect with a Set

    When the items you want to deduplicate are objects, a plain Set won't help because two objects with the same email are still distinct references. The right tool is a Map keyed by whatever derived value defines uniqueness for your domain.

    When you need to compute the intersection of two collections, building one of them into a Set once turns the whole operation into O(n + m).

  5. Challenge

    Lab complete

    Confirm the full suite is green

    Before finishing the lab, run the full test suite to confirm that every refactor works at both small-fixture and production volume. Nicely done. You took a customer-data pipeline that froze on 100,000 records and made it complete the same workload inside a tight performance budget without scaling up the hardware.

    You practiced three reusable patterns:

    • Build a Set once before a hot membership check.
    • Use a Set to deduplicate primitives in one pass.
    • Use a Map keyed by a derived value to deduplicate objects.

    Next, try spotting the same shape in your own code. Any loop or filter callback that calls .includes(...), .indexOf(...), or .some(...) against another collection may be a candidate for the same refactor.

About the author

Pluralsight’s AI authoring technology is designed to accelerate the creation of hands-on, technical learning experiences. Serving as a first-pass content generator, it produces structured lab drafts aligned to learning objectives defined by Pluralsight’s Curriculum team. Each lab is then enhanced by our Content team, who configure the environments, refine instructions, and conduct rigorous technical and quality reviews. The result is a collaboration between artificial intelligence and human expertise, where AI supports scale and efficiency, and Pluralsight experts ensure accuracy, relevance, and instructional quality, helping learners build practical skills with confidence.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight