Skip to content

Instantly share code, notes, and snippets.

@Oluwasetemi
Forked from bendc/recursion.js
Created November 14, 2016 03:00
Show Gist options
  • Save Oluwasetemi/28d268a0e21d133053eeee903bfc59e7 to your computer and use it in GitHub Desktop.
Save Oluwasetemi/28d268a0e21d133053eeee903bfc59e7 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