Intermediate Algorithm Scripting - Arguments Optional

Tell us what’s happening:
Describe your issue in detail here.
My codes are producing the required results on freecodecamp and also on my local environment, but cases are failing.

Please check the screenshot.

Your code so far
function curry(f){
return function(a){
return function(b){
return f(a, b);
}
}
}
function addTogether(a, b) {
const arr = ;
arr.push(a);
arr.push(b);
// console.log(arr);
if(arr.length == 2){
if(typeof a === ‘number’ && typeof b === ‘number’){
return a + b;
} else {
return undefined;
}
} else if(arr.length == 1 && typeof arr[0] === undefined){
return undefined;
}
}
let curriedSum = curry(addTogether);
console.log(curriedSum(2)([3]));
console.log(curriedSum(5)(7));

function curry(f){
    return function(a){
      return function(b){
        return f(a, b);
      }
    }
  }
function addTogether(a, b) {
  const arr = [];
  arr.push(a);
  arr.push(b);
  // console.log(arr);
  if(arr.length == 2){
    if(typeof a === 'number' && typeof b === 'number'){
      return a + b;
    } else {
      return undefined;
    }
  } else if(arr.length == 1 && typeof arr[0] === undefined){
    return undefined;
  } 
}
let curriedSum = curry(addTogether);
console.log(curriedSum(2)([3]));
console.log(curriedSum(5)(7));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Arguments Optional

Link to the challenge:

You are not handling the case where only one argument is passed here.

1 Like

Thanks for pointing it out.

1 Like