Skip to content

Instantly share code, notes, and snippets.

@chalu
Created February 19, 2018 11:13
Show Gist options
  • Save chalu/0a16c56fa3b1bb03e22a65a3b3334f80 to your computer and use it in GitHub Desktop.
Save chalu/0a16c56fa3b1bb03e22a65a3b3334f80 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