2732. Counter
My accepted JavaScript solution to LeetCode problem 2732, Counter, running in 41ms.
- Difficulty: Easy
- JavaScript
- Runtime 41ms
- Memory 53.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 41ms, memory 53.3MB, accepted 2026-01-01.
/**
* @param {number} n
* @return {Function} counter
*/
var createCounter = function(n) {
return function() {
return n++;
};
};
/**
* const counter = createCounter(10)
* counter() // 10
* counter() // 11
* counter() // 12
*/