Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1.  
  2. function repeat(operation, num) {
  3. if (num <= 0) {
  4. return;
  5. }
  6. operation();
  7. return function() {
  8. return repeat(operation, --num);
  9. };
  10. }
  11.  
  12. function trampoline(fn) {
  13. var args = Array.prototype.slice.call(arguments, 1);
  14. var result = fn.apply(null, args);
  15. while (!!result) {
  16. result = result();
  17. }
  18. }
  19.  
  20. module.exports = function(operation, num) {
  21. return trampoline(repeat, operation, num);
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement