Skip to content

Instantly share code, notes, and snippets.

@lawrencechen0921
Last active September 11, 2019 15:58
Show Gist options
  • Save lawrencechen0921/cb5754548d122916a8a46b6ce17a7a18 to your computer and use it in GitHub Desktop.
Save lawrencechen0921/cb5754548d122916a8a46b6ce17a7a18 to your computer and use it in GitHub Desktop.
start to use Javascript to make a recursion algorithms
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