Design a function createCounter
that takes an optional starting number.
The function should return another function which, when called for the first time,
returns the starting number (or 0 if no starting number is given).
Each subsequent call should return the next integer in sequence, increasing by 1
from the previous value.
Example:
const countUp = createCounter(); countUp(); // 0 countUp(); // 1 countUp(); // 2 const countFromFive = createCounter(5); countFromFive(); // 5 countFromFive(); // 6 countFromFive(); // 7
JavaScript Function
No test results yet
Click "Run" to execute tests