Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created May 10, 2022 12:18
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 honzabrecka/efe67ba758e02c09ecc7b43fd4cb34d5 to your computer and use it in GitHub Desktop.
Save honzabrecka/efe67ba758e02c09ecc7b43fd4cb34d5 to your computer and use it in GitHub Desktop.
const trampoline = (f, ...args) => {
let r = f(...args);
while (typeof r === 'function') r = r();
return r;
};
const f = (x, n) => {
return x < n ? f(x + 1, n) : 'done';
};
// console.log(f(0, 1000000));
const g = (x, n) => {
return x < n ? () => g(x + 1, n) : 'done';
};
console.log(trampoline(g, 0, 1000000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment