Skip to content

Instantly share code, notes, and snippets.

@shurane
Last active August 29, 2015 14:08
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 shurane/d16145e7e32a0eccd2a4 to your computer and use it in GitHub Desktop.
Save shurane/d16145e7e32a0eccd2a4 to your computer and use it in GitHub Desktop.
Mutual recursion is lots of fun.... not.
// Way #1
function a (num) {
console.log('a', num);
num = num + 1;
if (num > 1000)
{ return num; }
else {
setTimeout(function () { b(num); }, 1000);
}
}
function b (num) {
console.log('b', num);
num = num * 2;
setTimeout(function () { a(num); }, 1000);
}
setTimeout(a(1), 1000);
// Way #2: A better way.
// using async.whilst && _.compose
// in progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment