Advertisement
2666. Allow One Function Call
UnknownView on LeetCode
2666.ts
TypeScript
type JSONValue =
| null
| boolean
| number
| string
| JSONValue[]
| { [key: string]: JSONValue };
type OnceFn = (...args: JSONValue[]) => JSONValue | undefined;
function once(fn: Function): OnceFn {
let isCalled = false;
return function (...args) {
if (isCalled) {
return;
}
isCalled = true;
return fn(...args);
};
}
Advertisement
Was this solution helpful?