/*Intermediate Algorithm Scripting: Arguments Optional
Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.
For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
Calling this returned function with a single argument will then return the sum:
var sumTwoAnd = addTogether(2);
sumTwoAnd(3) returns 5.
If either argument isn't a valid number, return undefined.
**/
function addTogether(a,b) {
if(typeof a === 'number' && typeof b === 'number' || !isNaN(b)){
a+=b;
}if(typeof a === 'number' && !isNaN(a) && typeof b === 'number' && !isNaN(b)){
return a;
}if(typeof a === 'number' && !isNaN(a)){
var sumTwoAnd = function arr(e){
if(typeof a === 'number' && !isNaN(a) &&typeof e === 'number'){
e+=a; console.log(e); return e
}
}
sumTwoAnd(3);
return sumTwoAnd ;
}
}
addTogether(2);
/*
addTogether(2, 3) should return 5.
Passed
addTogether(2)(3) should return 5.
Passed
addTogether("http://bit.ly/IqT6zt") should return undefined.
Passed
addTogether(2, "3") should return undefined.
Passed
addTogether(2)([3]) should return undefined./
/*https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person/
Top comments (0)