Last active
May 23, 2016 16:49
-
-
Save daronwolff/bafb20a0472dd0645cbb94acb135574c to your computer and use it in GitHub Desktop.
Write a function that returns two functions that implement up/down counter
This file contains hidden or 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
| function counterf(n) { | |
| var n = n; | |
| var inc = function() { | |
| return n += 1; | |
| }; | |
| var dec = function() { | |
| return n -= 1; | |
| }; | |
| return { | |
| dec: dec, | |
| inc: inc | |
| } | |
| } | |
| var d = counterf(20); | |
| d.inc(); //21 | |
| d.dec() // 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment