Created
          April 25, 2020 11:23 
        
      - 
      
- 
        Save ins77/c89ecdb0981d8a35716909b05f7f469c to your computer and use it in GitHub Desktop. 
    magic
  
        
  
    
      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
    
  
  
    
  | const magic = (...rest) => { | |
| const sum = rest.reduce((acc, current) => acc + current, 0); | |
| const inner = (...args) => { | |
| return magic(inner.valueOf(), ...args); | |
| }; | |
| inner.valueOf = () => sum; | |
| return inner; | |
| }; | |
| magic(5, 2, -9).valueOf(); | |
| magic(5, 2, -8)(4) + 2; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment