Implement a function singleton(fn) that ensures the given function fn is called at most once.
Subsequent calls should return the same value returned by the first invocation.
Examples
let count = 0; const init = singleton(() => ++count); init(); // 1 init(); // 1 init(); // 1 // Even if called multiple times, only the first call executes the original function.
JavaScript Function
No test results yet
Click "Run" to execute tests