14 / 14

Array Cheatsheet.

javascript
Difficulty: 5/10
Topics: Array Methods, Performance & Memory, Data Transformation

Scenario Questions

0-2 years experience
  1. 1

    We have a list of user objects and we need to display only the active users, sorted by their last login date. How would you chain array methods to achieve this, and what happens to the original array when you do?

  2. 2

    Imagine you are building a shopping cart. When a user removes an item, you need to delete it from an array of items. How would you find and remove that item by its ID without leaving empty 'holes' in the array?

2-5 years experience
  1. 1

    A teammate wrote a search filter that uses .filter() inside a .map() loop to cross-reference two arrays of 5,000 items each, and the UI is freezing. How would you diagnose the performance bottleneck and rewrite this to run in linear time?

  2. 2

    We have a real-time dashboard receiving a stream of log events. The developer used unshift() to add new logs to the front of the array so they display first. As the log size grows, the app gets sluggish. Why is unshift causing issues here, and how would you refactor the data structure or rendering logic to fix it?

5-8 years experience
  1. 1

    We are building an undo/redo history stack for a collaborative design tool. The state history array can grow extremely large. How would you design this history manager to prevent memory leaks and ensure that state transitions remain O(1) while keeping memory usage bounded?

  2. 2

    In a high-throughput data visualization component, we need to process and render 100,000 data points every 16ms. Standard array methods like .map().filter().reduce() are causing garbage collection spikes and frame drops. How would you optimize this processing pipeline to avoid allocations and maintain 60fps?

8+ years experience
  1. 1

    Our enterprise monorepo has dozens of micro-frontends independently manipulating shared state arrays, leading to race conditions and unpredictable mutations. How would you design an architectural pattern or state-sharing contract to enforce immutability and predictable updates across these teams without introducing massive performance overhead?

  2. 2

    We are migrating a legacy Node.js service that processes multi-gigabyte CSV exports in memory using massive array structures, frequently hitting out-of-memory limits. How would you architect a streaming, buffer-backed solution to replace these arrays, and how would you roll this out safely without breaking downstream consumers?

Follow-up Questions

  • How does the V8 engine optimize sparse arrays versus dense arrays under the hood?
  • If memory is constrained, how would you process a 10GB array-like stream of JSON objects?
  • What are the performance implications of using the spread operator inside a reduce loop?