Last active
September 11, 2019 15:58
-
-
Save lawrencechen0921/cb5754548d122916a8a46b6ce17a7a18 to your computer and use it in GitHub Desktop.
start to use Javascript to make a recursion algorithms
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 factorial (num) { | |
if (num === 1) { | |
return num | |
} else { | |
return num * factorial(num - 1) | |
} | |
} | |
factorail(5) | |
#LIFO 觀念 | |
function last () { | |
console.log('後來才進堆疊') | |
} | |
function first () { | |
console.log('先進堆疊 - start') | |
last() | |
console.log('先進堆疊 - end') | |
} | |
first() // "先進堆疊 - start" -> "後來進堆疊" -> "先進堆疊 - end" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment