function addTogether() {
let args = Array.from(arguments)
return args.some(n => typeof n !== "number")
? undefined
: args.length > 1
? args.reduce((acc, n) => (acc += n), 0)
: n => (typeof n === "number" ? n + args[0] : undefined);
}
addTogether(2);
Would someone please help me understand how the above solution works to return a function if one argument is passed to addTogether function. thanks
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0
.
Challenge: Arguments Optional
Link to the challenge: