Allow One Function Call Lab
In this Allow One Function Call Lab, you will be tasked with creating a function that ensures the given function is called at most once. This new function will be identical to the original function but will return undefined
every time it is called after the first call.
For example, let's consider the following input:
const fn = (a, b, c) => a + b + c; const onceFn = once(fn); onceFn(1, 2, 3); // Returns 6 (a + b + c = 1 + 2 + 3) onceFn(2, 3, 6); // Returns undefined, as fn is not called
Now consider another example:
const fn = (a, b, c) => a * b * c; const onceFn = once(fn); onceFn(5, 7, 4); // Returns 140 (a * b * c = 5 * 7 * 4) onceFn(2, 3, 6); // Returns undefined, as fn is not called onceFn(4, 6, 8); // Returns undefined, as fn is not called
Constraints:
1 <= calls.length <= 10
1 <= calls[i].length <= 100
2 <= JSON.stringify(calls).length <= 1000
Your task is to complete the function in index.js
which ensures any provided function is called at most once, while also respecting the ESM import/export rules. In addition, complete the following challenges in the appropriate sequence that evaluates your code against the intended functionality.
Remember, the evaluation script is extremely important and must be implemented without any errors. Following the key points outlined earlier in this document, ensure proper handling of dependencies and adhere to the given format.