Skip to content

Instantly share code, notes, and snippets.

@richdouglasevans
Created July 16, 2015 19:42
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 richdouglasevans/0a15d38cb5e851d40a1e to your computer and use it in GitHub Desktop.
Save richdouglasevans/0a15d38cb5e851d40a1e to your computer and use it in GitHub Desktop.
Trampoline
function repeat(operation, num) {
if (num <= 0) {
return;
}
operation();
return function() {
return repeat(operation, --num);
};
}
function trampoline(fn) {
var args = Array.prototype.slice.call(arguments, 1);
var result = fn.apply(null, args);
while (!!result) {
result = result();
}
}
module.exports = function(operation, num) {
return trampoline(repeat, operation, num);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment