Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emilwijayasekara/leetcode-2620-counter-30-days-of-javascript-day-2

Leetcode Problem 2620 Counter - Function that takes an initial value n and returns a new function. The returned function, when called, will return n and then increment it for subsequent calls, creating a counter.
https://github.com/emilwijayasekara/leetcode-2620-counter-30-days-of-javascript-day-2

javascript leetcode leetcode-javascript leetcode-solutions

Last synced: 2 days ago
JSON representation

Leetcode Problem 2620 Counter - Function that takes an initial value n and returns a new function. The returned function, when called, will return n and then increment it for subsequent calls, creating a counter.

Awesome Lists containing this project

README

        

# LeetCode (30 Days of JavaScript)

## About the problem
- *Problem Number* : 2620
- *Problem Name* : [Counter](https://leetcode.com/problems/counter/)
- *Problem difficulty* : Easy 🟢
- *Programming language used* - JavaScript

## Problem

Given an integer n, return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).

Example 1:
```cpp
Input:
n = 10
["call","call","call"]
Output: [10,11,12]
Explanation:
counter() = 10 // The first time counter() is called, it returns n.
counter() = 11 // Returns 1 more than the previous time.
counter() = 12 // Returns 1 more than the previous time.
```
The function returned by createHelloWorld should always return "Hello World".`

Example 2:
```cpp
Input:
n = -2
["call","call","call","call","call"]
Output: [-2,-1,0,1,2]
Explanation: counter() initially returns -2. Then increases after each sebsequent call.
```
Any arguments could be passed to the function but it should still always return "Hello World".

Constraints:
`-1000 <= n <= 1000
0 <= calls.length <= 1000
calls[i] === "call"`

### If you have suggestions for improvement or would like to contribute to this solution, feel free to create a pull request. 🙌😇