Closures & Functions
Function Once Wrapper
easyJS SpecificJS / TS3 tests
Problem Statement
Implement a function `once(fn)` that ensures `fn` can only be called once. Subsequent invocations return the value returned by the first call, without executing `fn` again.
Examples
Example 1: let counter = 0; const init = once(() => ++counter); init(); // 1 init(); // 1 console.log(counter); // 1
JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
3 test cases. No second person needed.