Skip to content

Commit 5c2f0e6

Browse files
Create: 2620-counter.ts
1 parent 2effbe1 commit 5c2f0e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

typescript/2620-counter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function createCounter(n: number): () => number {
2+
return function() {
3+
return n++;
4+
}
5+
}
6+
7+
8+
/**
9+
* const counter = createCounter(10)
10+
* counter() // 10
11+
* counter() // 11
12+
* counter() // 12
13+
*/

0 commit comments

Comments
 (0)