algorithms/addTogether.js

9 lines
297 B
JavaScript
Raw Permalink Normal View History

2024-01-12 07:01:06 -05:00
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));