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

Cycle

语言
JSTS

Implement a function that takes one or more values and returns a function that cycles through those values each time it is called.

Examples

const helloFn = cycle('hello');
console.log(helloFn()); // "hello"
console.log(helloFn()); // "hello"
const onOffFn = cycle('on', 'off');
console.log(onOffFn()); // "on"
console.log(onOffFn()); // "off"
console.log(onOffFn()); // "on"

Source