Skip to content

Instantly share code, notes, and snippets.

@AutoSponge
Last active December 18, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AutoSponge/5715822 to your computer and use it in GitHub Desktop.
Save AutoSponge/5715822 to your computer and use it in GitHub Desktop.
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