Having a bit of trouble with this challenge
Am i supposed to consider using currying, or creating functions for this challenge Im confused by the instructions and maybe i want more test cases… idk
Having a bit of trouble with this challenge
Am i supposed to consider using currying, or creating functions for this challenge Im confused by the instructions and maybe i want more test cases… idk
You use currying in one particular case - only if one argument has been provided, otherwise you just return the sum of arguments
Ive been trying to best understand the instructions, I think for this challenge its more of a roadblock than any previous exercise!
here is what i have so far, the comments are notes taken from the guide page
function addTogether(a, b) {
//if(arguments.length<=2){
//It has to check if it has one or two arguments passed. More are ignored.
//It has to check if any of the numbers are actual numbers, otherwise return undefined and stop the program right there.
if (Number(a) || Number(b)) {
if (arguments.length == 2) {
//It has to add two numbers passed as parameters and return the sum.
function add(a) {
return function(b) {
return a + b;
};
}
add(a)(b);
} //length2
else if (arguments.length == 1) {
//If it has only one argument then it has to return a function that uses that number and expects another one, to then add it.
function add(a) {
return function(b) {
return a;
};
}
add(a)(b);
} //length1
} else {
return undefined;
}
} //function
//}
//addTogether(2,3);