Skip to content

Instantly share code, notes, and snippets.

@colibie
Created April 19, 2020 14:27
Show Gist options
  • Save colibie/1bd89032b99bcd17e43aa1d223e3e8fe to your computer and use it in GitHub Desktop.
Save colibie/1bd89032b99bcd17e43aa1d223e3e8fe to your computer and use it in GitHub Desktop.
A comparison of recursive hello.js and iterative hello.js
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