Created
September 21, 2020 03:54
-
-
Save krutoo/0a8e8fa1b364e40802936cd5bfb7d594 to your computer and use it in GitHub Desktop.
sum(1, 2)(3)(4, 5) == 15
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
const add = (a, b) => a + b; | |
const sumList = numbers => numbers.reduce(add, 0); | |
const sum = (...startValues) => { | |
let total = sumList(startValues); | |
const fn = (...values) => (total += sumList(values), fn); | |
fn.valueOf = () => total; | |
return fn; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment