f(1)(2)(3)() // === 6
f(1, 2, 3)() // === 6
f(1, 2)(3)() // === 6
f(1, 3)(4, 6)(10)() // === 24
function sum(...v1) {
const s = v1.reduce((acc, n) => acc + n, 0);
const f = (...v2) => v2.length ? sum(...v2, s) : s;
return v1.length ? f : s;
}