Last active
December 18, 2015 03:08
-
-
Save AutoSponge/5715822 to your computer and use it in GitHub Desktop.
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
function count(seed, d) { | |
var i = seed; | |
return function counter(n) { | |
i += (n || d); | |
return function () { | |
return i; | |
}; | |
}; | |
} | |
var i = count(1, 2); | |
console.assert(i()() === 3); | |
console.assert(i()() === 5); | |
/**/ | |
function range(seed, limit, d) { | |
var i = seed; | |
return function counter(n) { | |
i += (n || d); | |
return i > limit ? null : function () { | |
return i; | |
}; | |
}; | |
} | |
var inc = range(1, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment