2.1. No extra variables: We can make do by using the fn variable itself as a flag. After calling fn(), we set the variable to null. Before calling fn(), we check that it's not null:
const once = fn => {
return (...args) => {
fn && fn(...args);
fn = null;
};
};
2.2. Alternating functions: In a manner similar to what we did in the previous question, we call the first function and then switch functions for the next time. Here, we used a destructuring assignment to write the swap in a more compact manner. For more information, refer to
The rest of the chapter is locked