Skip to content

Commit 8314fc1

Browse files
committed
test out TS
1 parent 93cd87f commit 8314fc1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

javascript/Counter2620.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
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).
3+
*/
4+
const createCounter = n => () => n++;
5+
6+
7+
const counter = createCounter(5);
8+
console.log(counter()); // 5
9+
console.log(counter()); // 6
10+
console.log(counter()); // 7
11+
console.log(counter()); // 8
12+

typescript/Counter2620.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const createCounter = (n: number): () => number => () => n++;
2+
3+
const counter2620 = createCounter(2620);
4+
console.log(counter2620()); // 2620
5+
console.log(counter2620()); // 2621
6+
console.log(counter2620()); // 2622
7+
console.log(counter2620()); // 2623

0 commit comments

Comments
 (0)