Skip to content

Instantly share code, notes, and snippets.

@gorakhargosh
Last active October 8, 2015 21:30
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 gorakhargosh/d4e3d8d20ed5da0643fe to your computer and use it in GitHub Desktop.
Save gorakhargosh/d4e3d8d20ed5da0643fe to your computer and use it in GitHub Desktop.
How to interleave 10 and 9 (while also causing a stack overflow). Code only works in language that has function hoisting.
a(10, 1);
function a(n, steps) {
console.log(n, steps);
if (n == 1) {
return 0;
}
return b(n - 1, steps+1);
}
function b(n, steps) {
console.log(n, steps);
if (n == 1) {
return 0;
}
return a(n + 1, steps+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment