- 
      
- 
        Save inem/290910 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | var A_reduce = [].reduce; | |
| Array.prototype.reduce = function reduce (callback, initialValue) { | |
| var operator = callback; | |
| return typeof operator == 'string' && /^[ +*/%-><!&|^?,.]/.test(operator) | |
| ? eval(this.join(operator)) | |
| : A_reduce.apply(this, arguments) | |
| }; | |
| [1,2,3,4].reduce('+') // 10 | |
| [1,2,3,4].reduce('*') // 24 | |
| [2, 0, 1].reduce('&&') // 0 | |
| [2, 0, 1].reduce('||') // 2 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment