-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8033ef8
commit c7a834e
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type ReturnObj = { | ||
increment: () => number | ||
decrement: () => number | ||
reset: () => number | ||
} | ||
|
||
function createCounter(init: number): ReturnObj { | ||
let currentValue = init | ||
|
||
return { | ||
increment() { | ||
currentValue++ | ||
return currentValue | ||
}, | ||
decrement() { | ||
currentValue-- | ||
return currentValue | ||
}, | ||
reset() { | ||
currentValue = init | ||
return currentValue | ||
}, | ||
} | ||
} | ||
|
||
export { createCounter } | ||
|
||
/** | ||
* const counter = createCounter(5) | ||
* counter.increment(); // 6 | ||
* counter.reset(); // 5 | ||
* counter.decrement(); // 4 | ||
*/ | ||
|
||
// 2023/05/07 done | ||
// Runtime 74 ms Beats 56.14% | ||
// Memory 45.4 MB Beats 73.68% |