Skip to content

Instantly share code, notes, and snippets.

@gorakhargosh
Last active October 8, 2015 21:30
Show Gist options
  • Select an option

  • Save gorakhargosh/d4e3d8d20ed5da0643fe to your computer and use it in GitHub Desktop.

Select an option

Save gorakhargosh/d4e3d8d20ed5da0643fe to your computer and use it in GitHub Desktop.

Revisions

  1. gorakhargosh revised this gist Oct 8, 2015. No changes.
  2. gorakhargosh created this gist Oct 8, 2015.
    17 changes: 17 additions & 0 deletions mutual-recursion.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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);
    }