Created
          January 12, 2018 13:26 
        
      - 
      
- 
        Save jooyunghan/0085a0f10edf393790e5477c1d37010f to your computer and use it in GitHub Desktop. 
    trampoline을 이용한 상호재귀
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function even(n) { | |
| if (n === 0) return true; | |
| else return () => odd(n-1); | |
| } | |
| function odd(n) { | |
| if (n === 0) return false; | |
| else return () => even(n-1); | |
| } | |
| function trampoline(f) { | |
| while (typeof f === 'function') { | |
| f = f(); | |
| } | |
| return f; | |
| } | |
| console.log(trampoline(() => even(100000))); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment