Skip to content

Latest commit

 

History

History
73 lines (59 loc) · 1.26 KB

_2620. Counter.md

File metadata and controls

73 lines (59 loc) · 1.26 KB

2620. Counter

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 09, 2024

Last updated : July 20, 2024


Related Topics : N/A

Acceptance Rate : 81.53 %


Solutions

JavaScript

/**
 * @param {number} n
 * @return {Function} counter
 */
var createCounter = function(n) {
    var cnt = n - 1;
    return function() {
        cnt++;
        return cnt;
    };
};
/**
 * @param {number} n
 * @return {Function} counter
 */
var createCounter = function(n) {
    return function() {
        return n++;
    };
};

/** 
 * const counter = createCounter(10)
 * counter() // 10
 * counter() // 11
 * counter() // 12
 */
/**
 * @param {number} n
 * @return {Function} counter
 */
var createCounter = function(n) {
    return () => n++;
};