0Pricing
JavaScript Academy · Lesson

Big-O basics, hot vs cold paths (beginner wins)

Use Big-O intuition and focus on hot paths. Replace nested scans with Set/Map, avoid repeated work, and keep code small and clear.

Big picture

Goal: Quick wins without complex theory.

  • Big-O intuition: avoid double loops
  • Hot vs cold paths: optimize what runs most
  • Set/Map for fast lookups
  • Do work once, reuse results
Big-O basics, hot vs cold paths (beginner wins) — illustration 1

Nested scan = costly

Nesting scans multiplies work. Each includes walks the array again.

// Bad pattern: nested scan for membership (can be ~O(n^2))
const haystack = ["a","b","c","d","e"];
const needles = ["b","e","x"];
const foundSlow = [];

for (const n of needles) {
  // includes scans the array each time
  if (haystack.includes(n)) {
    foundSlow.push(n);
  }
}
console.log("slow found:", foundSlow);
Big-O basics, hot vs cold paths (beginner wins) — illustration 2

All lessons in this course

  1. Big-O basics, hot vs cold paths (beginner wins)
  2. Avoiding leaks — closures, timers, references
  3. Profiling intro (Node/DevTools) — tiny timing habits
← Back to JavaScript Academy