Skip to content

Instantly share code, notes, and snippets.

@takuyadev
Last active June 4, 2023 02:01
Show Gist options
  • Save takuyadev/58789ad107d88d9ea4313f106c12db1b to your computer and use it in GitHub Desktop.
Save takuyadev/58789ad107d88d9ea4313f106c12db1b to your computer and use it in GitHub Desktop.
2665. Counter II
const createCounter = function (init) {
// Keep in memory by initiating a count
let initialValue = init
let count = init
// Return methods for the function
return {
increment: () => ++count,
decrement: () => --count,
reset: () => count = initialValue
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment