Skip to content

Instantly share code, notes, and snippets.

@silianlinyi
Created November 21, 2013 13:35
Show Gist options
  • Save silianlinyi/7581661 to your computer and use it in GitHub Desktop.
Save silianlinyi/7581661 to your computer and use it in GitHub Desktop.
构建一个带尾递归的函数。因为它会返回自身调用的结果,所以它是尾递归。
function factorial(i, a) {
a = a || 1;
if(i < 2) {
return a;
}
return factorial(i - 1, a * i);
}
factorial(4); // => 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment