Skip to content

Instantly share code, notes, and snippets.

@Developerayo
Forked from chalu/if-correct-recursion.js
Created February 19, 2018 18:50
Show Gist options
  • Save Developerayo/bfd6961c2d2c89142e6bfc24b4c38778 to your computer and use it in GitHub Desktop.
Save Developerayo/bfd6961c2d2c89142e6bfc24b4c38778 to your computer and use it in GitHub Desktop.
A number of countdown implementations to review
const countdownA = (limit) => {
for(let i = limit; i >= 1; i--) {
console.log('Now @ ' + i);
}
};
const countdownB = (limit) => {
console.log('Now @ ' + limit);
if (limit === 1) return 1;
countdownB(limit);
};
const countdownC = (limit) => {
console.log('Now @ ' + limit);
if (limit === 1) return 1;
countdownC(limit - 1);
};
const countdownD = (limit) => {
console.log('Now @ ' + limit);
if (limit = 1) return 1;
countdownD(limit--);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment