algorithms/addTogether.js
2024-01-12 07:01:06 -05:00

9 lines
No EOL
297 B
JavaScript

function addTogether() {
const arr = Array.from(arguments);
return arr.some(n => typeof n !== "number")
? undefined
: arr.length > 1
? arr.reduce((a, b) => a + b)
: n => (typeof n === "number" ? n + arr[0] : undefined);
}
console.log(addTogether(5)(7));