Created
January 20, 2010 10:58
-
-
Save NV/281765 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
| function count(x, i) { | |
| var i = i || 1; | |
| console.log(i); | |
| if (i < x) count(x, i+1); | |
| } | |
| count(5) // 1, 2, 3, 4, 5 | |
| function count_with_depth_limit (x, start) { | |
| var i = start || 1; | |
| var depth = 10; // глубина стека | |
| (function f() { | |
| console.log(i); | |
| i++; | |
| depth--; | |
| if (x >= i && depth > 0) f(); | |
| })(); | |
| if (i <= x) count_with_depth_limit(x, i) | |
| } | |
| count_with_depth_limit(1000) // 1, 2, 3, ... , 10000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment