Skip to content

Instantly share code, notes, and snippets.

@GianCastle
Forked from bendc/recursion.js
Created October 2, 2017 19:37
Show Gist options
  • Select an option

  • Save GianCastle/b692168a66f7e28e6dc6d7dbd88901d7 to your computer and use it in GitHub Desktop.

Select an option

Save GianCastle/b692168a66f7e28e6dc6d7dbd88901d7 to your computer and use it in GitHub Desktop.
Functional loop
const loop = (() => {
const recur = (callback, count, i=0) => {
if (i == count-1) return callback(i);
callback(i);
return recur(callback, count, i+1);
};
return (callback, count) => {
if (count > 0) return recur(callback, count);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment