Skip to content

Instantly share code, notes, and snippets.

@NV
Created January 20, 2010 10:58
Show Gist options
  • Select an option

  • Save NV/281765 to your computer and use it in GitHub Desktop.

Select an option

Save NV/281765 to your computer and use it in GitHub Desktop.
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