JS | "Create Counter Function" | Time Complexity O(1) | 33ms Beats 99.69%
---\n\n# Intuition\nThe goal is to implement a counter function that begins at an integer n and increments each time it is called.\n\n# Approach\nDefine a count
---\n\n# Intuition\nThe goal is to implement a counter function that begins at an integer n and increments each time it is called.\n\n# Approach\nDefine a counter function that uses a variable to track the current count, starting from a given integer **n**. The function returns another function that increments and returns this count each time it\'s called.\n\n# Complexity\n- **Time Complexity** O(1) Each call is handled in constant time.\n- **Space Complexity** O(1) Uses a fixed amount of extra space.\n\n# Code\n```\n/**\n * @param {number} n\n * @return {Function} counter\n */\n\n\nvar createCounter = function(n) {\n    let n_ = n;\n    return function() {\n        return n_++;\n    };\n};\n\n\n/** \n * const counter = createCounter(10)\n * counter() // 10\n * counter() // 11\n * counter() // 12\n */\n```\n\n---
['JavaScript']