2665. Counter II
https://leetcode.com/problems/counter-ii
Javascript
var createCounter = function(init) {
const origin = init
let current = init
return {
increment: () => {
return ++current
},
decrement: () => {
return --current
},
reset: () => {
current = init
return current
}
}
};
Typescript
type ReturnObj = {
increment: () => number,
decrement: () => number,
reset: () => number,
}
var createCounter = function(init): ReturnObj {
const origin = init
let current = init
return {
increment: () => {
return ++current
},
decrement: () => {
return --current
},
reset: () => {
current = init
return current
}
}
};