As reported: Oracle OCI SMTS (UI) / SDE3 (Bengaluru), screening round (elimination), Feb 2025 — after resume and React questions, Promises/async-await and the event loop: write a debounce in vanilla JS; then ways to improve app performance.
Write debounce(fn, wait) in plain JavaScript. It returns a new function that, when called repeatedly, invokes fn only after wait milliseconds have passed without another call. The call that finally runs uses the latest arguments and the caller's this.
Typical use: run a search request only after the user stops typing.
const onInput = debounce((q) => search(q), 300);
input.addEventListener("input", (e) => onInput(e.target.value));