Frontend Machine Coding Practice
Practice the exact utility and algorithm challenges asked in Round 1 & 2 at top tech companies. Run live unit test suites in the browser, measure runtime execution, and master Lead-level trade-off explanations.
Implement Debounce with Immediate & Cancel Support
Implement a `debounce(fn, delay, options)` function that delays invoking `fn` until after `delay` milliseconds have elapsed since the last time the debounced function was invoked. It must preserve `this` and arguments, and provide a `.cancel()` method.
Implement Deep Clone with Circular Reference Handling
Write a `deepClone(obj)` function that creates a deep duplicate of nested objects, arrays, Dates, and RegExp instances while handling circular references safely without infinite recursion.
Implement Promise.all Polyfill
Implement `promiseAll(iterable)` which returns a Promise that resolves when all input promises have resolved (preserving input order) or rejects as soon as the first promise rejects.
Implement Array.prototype.flat with Depth Parameter
Implement a function `flatten(arr, depth = 1)` that flattens nested arrays recursively up to the specified depth limit without using native `Array.prototype.flat()`.
Implement LRU (Least Recently Used) Cache
Design and implement a data structure for Least Recently Used (LRU) Cache supporting `get(key)` and `put(key, value)` in O(1) time complexity.
Implement Custom EventEmitter (Pub/Sub Pattern)
Implement a custom `EventEmitter` class supporting `on(event, listener)`, `off(event, listener)`, `emit(event, ...args)`, and `once(event, listener)`. Ensure unsubscribing works reliably and listeners do not leak.
Implement Async Scheduler with Max Concurrency
Implement a `TaskScheduler(concurrency)` class with an `add(task)` method where `task` is a function returning a Promise. The scheduler must ensure that at most `concurrency` tasks execute concurrently. When a task completes, the next queued task must begin immediately.
Find Top K Frequent Elements in an Array (Hash Map + Bucket Sort)
Given an integer array `nums` and an integer `k`, return the `k` most frequent elements in O(N) time complexity. You may return the answer in any order.
Implement Custom Promise Polyfill (Promises/A+ Microtask Chaining)
Implement a custom `MyPromise` class from scratch supporting constructor executor, `.then()`, `.catch()`, chaining, and asynchronous microtask execution.