Created
April 19, 2020 14:27
-
-
Save colibie/1bd89032b99bcd17e43aa1d223e3e8fe to your computer and use it in GitHub Desktop.
A comparison of recursive hello.js and iterative hello.js
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 hello(i) { | |
if (i < 0) return; // base case | |
console.log(i); | |
hello(--i); // recursive call | |
} | |
hello(5); // output: 5 4 3 2 1 0 | |
function hello(i) { | |
if (i < 0) return; // base case | |
hello(--i); // recursive call | |
console.log(i); // statement after recursive call | |
} | |
hello(5); //output -1 0 1 2 3 4 -whooah what happened here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment