Skip to content

Instantly share code, notes, and snippets.

@hasinhayder
Last active August 29, 2015 14:15
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 hasinhayder/b2f61dc219557eb9e06d to your computer and use it in GitHub Desktop.
Save hasinhayder/b2f61dc219557eb9e06d to your computer and use it in GitHub Desktop.
counter problem :)
var counter = function(arg){
var local;
function incr(arg2){
arg2 = arg2 == undefined ? 1 : arg2;
return !local ? (local = arg2, incr) : (local += arg2, local);
}
return incr(arg);
}
var cnt = counter(5);
cnt();
cnt();
console.log(cnt(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment