The "Allow One Function Call interview question" is a JavaScript/TypeScript closure problem. You are asked to write a higher-order function that takes another function as an argument and returns a new version of that function. This new version should only be allowed to run once. On the first call, it should return the actual result; on any subsequent calls, it should return undefined, regardless of the arguments passed.
Companies like Yandex and Microsoft use the "Allow One Function Call coding problem" to test a candidate's understanding of Closures and Higher-Order Functions. It evaluates whether you know how to maintain state (a boolean flag) inside a function's scope that persists across multiple invocations. This is a common pattern for initialization logic or preventing duplicate API calls.
This problem uses the Closure and Wrapper pattern.
hasBeenCalled = false) inside the outer function.hasBeenCalled.hasBeenCalled is false, set it to true and call the original function using .apply() or spread syntax.hasBeenCalled is true, return undefined.Original function: add(a, b) => a + b.
Wrapped function: onceAdd = once(add).
onceAdd(2, 3) -> hasBeenCalled is false. Set it to true. Return 5.onceAdd(4, 5) -> hasBeenCalled is true. Return undefined.onceAdd(1, 1) -> hasBeenCalled is true. Return undefined.(a, b, c...) from the wrapper to the original function.this context if the function is meant to be used as a method (though less common in simple versions).Master closures! They are a fundamental part of modern JavaScript. Practice creating "decorators" or "wrappers" that modify the behavior of functions (like throttle, debounce, or memoize).