Last active
August 29, 2015 14:23
-
-
Save dmi3y/ba14b8fa83a3fe47cef4 to your computer and use it in GitHub Desktop.
Countdowns
This file contains 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
function setCountDown(n) { | |
n = n || 5; | |
for ( var i = 0; i <= n; i++ ) { | |
(function() { | |
var j = n - i; | |
setTimeout(function() { | |
console.log(j); | |
}, 1000 * i); | |
}()); | |
} | |
} |
This file contains 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
function* countdown(num) { | |
while (true) { | |
yield num--; | |
} | |
} | |
function setCountDown(n) { | |
n = n || 5; | |
var cd = countdown(n); | |
for(var i = 0; i <= n; i++) { | |
setTimeout(function() { | |
console.log(cd.next().value); | |
}, 1000 * i); | |
} | |
} |
This file contains 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
function setCountDown(n) { | |
n = n || 5; | |
(function cd(i) { | |
if ( i >= 0 ) { | |
setTimeout(function() { | |
console.log(i); | |
cd(--i); | |
}, 1000); | |
} | |
}(n)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment