9 lines
No EOL
297 B
JavaScript
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)); |