Skip to content

Instantly share code, notes, and snippets.

@MikeDigitize
Last active May 13, 2017 22:26
Show Gist options
  • Save MikeDigitize/5d87f57f87c29e2032c852c7fef1b3d5 to your computer and use it in GitHub Desktop.
Save MikeDigitize/5d87f57f87c29e2032c852c7fef1b3d5 to your computer and use it in GitHub Desktop.
/* without making `counter` a global variable refactor callMe
so the recursion it's attempting works correctly
and it logs 'Finished' when complete
var callMe = function() {
const counter = 0;
if(counter == '10') {
console.log('Finished');
}
counter++;
callMe();
}
callMe();
*/
var _callMe = (function() {
let counter = 0;
return function callMe() {
if(counter === 10) {
console.log('Finished');
}
else {
counter++;
callMe();
}
}
})();
_callMe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment