Skip to content

Instantly share code, notes, and snippets.

@krutoo
Created September 21, 2020 03:54
Show Gist options
  • Save krutoo/0a8e8fa1b364e40802936cd5bfb7d594 to your computer and use it in GitHub Desktop.
Save krutoo/0a8e8fa1b364e40802936cd5bfb7d594 to your computer and use it in GitHub Desktop.
sum(1, 2)(3)(4, 5) == 15
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