Problem: 2620. 计数器
123456789101112131415161718
/** * @param {number} n * @return {Function} counter */var createCounter = function(n) { var a=n; return function() { a=a+1; return a-1; };};/** * const counter = createCounter(10) * counter() // 10 * counter() // 11 * counter() // 12 */
1234567891011121314151617
/** * @param {number} n * @return {Function} counter */var createCounter = function(n) { var a=n; return function() { return a++; };};/** * const counter = createCounter(10) * counter() // 10 * counter() // 11 * counter() // 12 */
123456789101112131415
/** * @param {number} n * @return {Function} counter */var createCounter = function(n) { var a=n; return ()=>a++};/** * const counter = createCounter(10) * counter() // 10 * counter() // 11 * counter() // 12 */