Skip to content

Instantly share code, notes, and snippets.

@charlesroper
Last active March 4, 2021 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesroper/8de95087e618f9662b65e8ba2760819a to your computer and use it in GitHub Desktop.
Save charlesroper/8de95087e618f9662b65e8ba2760819a to your computer and use it in GitHub Desktop.
function countup (n) {
console.log(`we are in ${arguments.callee.name}(${n})`);
console.log(`is ${n} < 1?`, n < 1);
if (n < 1) {
console.log(`so we're going to return [] back to the caller\n↓`);
return [];
}
console.log(`so we call countup(${n-1})\n↓`);
const countArray = countup(n-1);
console.log(`we are back in ${arguments.callee.name}(${n})`);
console.log(`now we push ${n} into countArray, which is currently [${countArray}]\n↓`);
countArray.push(n);
return countArray;
}
console.log(countup(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment