function addTogether() {
let args = Array.from(arguments);
let temp = args.map(item => Number.isInteger(item));
if (temp.includes(false)) {
return undefined;
}
if (args.length == 2) {
return args[0] + args[1];
} else if (args.length == 1) {
// This returned function needs to check if temp
// is a valid function argument
return (temp) => temp + args[0];
}
}
console.log(addTogether(2)([3]));
For what its worth, it would help others read and debug your code if you use some clearer formatting and variable names.
Thanks for the advice, @JeremyLT ! I’ll definitely take it into account!
After implementing what you’ve said, this seems to be an appropriate version of the code:
function addTogether() {
let args = Array.from(arguments);
let temp = args.map(item => Number.isInteger(item));
if (temp.includes(false)) { return undefined; }
if (args.length == 2) {
return args[0] + args[1];
}
else if (args.length == 1) {
// check if x is a valid function argument
return function (x) {
if (Number.isInteger(x)) {
return x + args[0];
}
else {
return undefined;
}
}
}
}
console.log(addTogether(2)([3]));