Closure-based call counter
JavaScript
Easy
closures
Task «Closure-based call counter»
Create a function `createCounter` that takes an initial value (an integer) and returns a new function. The returned function increments the counter by 1 on each call and returns the current value. The initial value can be any integer. If no initial value is passed, it should be considered equal to 0.
Input Format
The input is a single integer — the initial value of the counter. If the number is not specified, assume it is equal to 0.
Output Format
After each call to the returned function, the current counter value is displayed. For testing purposes, the returned function will be called several times, and the results will be output separated by spaces.
Examples
Example 1
INPUT
5
OUTPUT
6 7 8 9 10
Example 2
INPUT
0
OUTPUT
1 2 3 4 5
Example 3
INPUT
3
ВойнаИмир Толстой 1869
ОтцыИдети Тургенев 1862
ПреступлениеИнаказание Достоевский 1866
2
Толстой 1869
Пушкин 1837
OUTPUT
Для задачи createCounter ожидается последовательность чисел, начиная с 3: 3 4 5 6 7 (или аналогично, в зависимости от количества вызовов, но в тесте не указано количество вызовов).
Example 4
INPUT
2
АннаКаренина Толстой 1877
Воскресение Толстой 1899
2
Толстой 1877
Толстой 1899
OUTPUT
Для задачи createCounter ожидается последовательность чисел, начиная с 2: 2 3 4 (или аналогично, в зависимости от количества вызовов, но в тесте не указано количество вызовов).
main.js