Enjoy 20% off all plans by following us on social media. Check out other promotions!

Make Counter

语言
JSTS

Implement a function makeCounter that accepts an optional integer value and returns a function. When the returned function is called initially, it returns the initial value if provided, otherwise 0. The returned function can be called repeatedly to return 1 more than the return value of the previous invocation.

Examples

const counter = makeCounter();
counter(); // 0
counter(); // 1
counter(); // 2

With a custom initial value:

const counter = makeCounter(5);
counter(); // 5
counter(); // 6
counter(); // 7

公司

高级版功能购买高级版以查看出题公司。
查看计划