Last active
May 13, 2017 22:26
-
-
Save MikeDigitize/5d87f57f87c29e2032c852c7fef1b3d5 to your computer and use it in GitHub Desktop.
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
/* 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