Created
September 16, 2020 14:30
-
-
Save safareli/ee8ecdf8aeb20616733a3b344af4b98d to your computer and use it in GitHub Desktop.
This file contains 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
sum(1, 2, 3, 4) == 10 // true | |
sum(1, 2, 3, 4)(1, 2, 3, 4) == 20 // true | |
sum(1)(2)(3)(4)(1)(2)(3)(4) == 20 // true | |
function sum(...args) { | |
function res(...args2) { | |
return sum(_sum(args), _sum(args2)) | |
} | |
// https://javascript.info/object-toprimitive | |
res[Symbol.toPrimitive] = () => _sum(args) | |
return res | |
} | |
function _sum(arr) { | |
return arr.reduce((a,b) => a + b, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@atesgoral if you don't pass in 0