Hi there!
Help to understand, plz, why we need to return - return addsecond - if we not return it cause error ‘addTogether(…) is not a function’…?
why ‘return first + second’ not enough?
And - what is the place to where 'return addsecond ’ - ?
this code is part of solution2 freeCodeCamp Challenge Guide: Arguments Optional
for 2 numbers as arguments
function addTogether() {
const [first, second] = arguments;
if (arguments.length === 1) { // CURRYING
function addsecond(second) {
return first + second;
}
return addsecond; // *** Note: returning a *function*
}
return first + second;
}
and where is the returning the function in this case?
function addTogether() {
var [fst,scn] = arguments;
var isNum = function(arg) { return Number.isFinite(arg); };
if (arguments.length === 1 && isNum(fst)) {
return function(dop) { //CURRY scn
if (isNum(dop)) {
return fst + dop;
}
}; // *** WHERE is returning unnamed function??
}
else if (arguments.length === 2 && isNum(fst) && isNum(scn)) {
return fst + scn;
}
}
If you now where it explained in details, plz, provide the link