Scrittura di Algoritmi Intermedio - Argomenti facoltativi

Tell us what’s happening:

The penultimate and the third last tests cannot be overcome because the round brackets of the arguments are missing.

Your code so far

function addTogether(...args) {

  let argomenti = args.slice();

  if(typeof argomenti[0] == "number"){
    if(typeof argomenti[1] == "number")
    return argomenti[0] + argomenti[1];
  if(argomenti.length == 1)
  return () => addTogether(argomenti[0] + argomenti[1]);
  }

}

addTogether(2,3);

Your browser information:

Lo user agent è: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Scrittura di Algoritmi Intermedio - Argomenti facoltativi

Ciao @baronemanu109

addTogether(5)(7) should return 12.

La tua funzione non prende in considerazione il currying di una funzione con più argomenti.

addTogether(2)([3]) should return undefined.

Non viene gestita la situazione in cui il secondo argomento sottoposto a currying è un array.

Buona programmazione

Tell us what’s happening:

I tried to manage the currying but continues to give me error in the penultimate and third test.

Your code so far

function addTogether() {

  let [first,second] = arguments;

  if(typeof first == "number"){
    if(typeof second == "number")
        return first + second;
  if(arguments.length == 1)
      return () => addTogether(first + second);
  }

}

addTogether(2,3);

Your browser information:

Lo user agent è: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Scrittura di Algoritmi Intermedio - Argomenti facoltativi

This isn’t a function that meets the requirements for the returned function. What is the returned function supposed to do again?

Tell us what’s happening:

I handled the array case as a second argument but still didn’t complete the test

Your code so far

function addTogether() {
  let [first,second] = arguments;

  if(typeof first == "number"){
    if(typeof second == "number")
      return first + second;
    if(arguments.length == 1)
      return () => addTogether(first + second);
  }else if(typeof second == "object"){
    return undefined;
  }

}

addTogether(2,3);

Your browser information:

Lo user agent è: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Scrittura di Algoritmi Intermedio - Argomenti facoltativi

Thi still is not a function that meets the requirements of the function that is supposed to be returned