No estoy entendiendo el ejercicio!

Cuéntanos qué está pasando:
Describe tu problema en detalle aquí.
No estoy entendiendo para modificar la funcion con parametros rest y estuve buscando informacion y no logro entenderlo…!!! si alguien me podria ayudar.

  **Tu código hasta el momento**

const sum = (x, y, z) => {
const args = [x, y, z];
return args.reduce((a, b) => a + b, 0);
}
  **Información de tu navegador:**

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38

Desafío: Utiliza el parámetro rest con parámetros de función

Enlaza al desafío:

The rest operator will gather the remaining items into an array. So, if I have a function like:

const concatenateThreeStrings = (str1, str2, str3) => {
  return str1 + str2 + str3;
}

That works, but what about using the rest operator instead:

const concatenateThreeStrings = (...strArr) => {
  return strArr[0] + strArr[1]  + strArr[2] ;
}

Actually, now that they are in an array, I can just use join:

const concatenateStrings = (...strArr) => {
  return strArr.join('');
}

Or even simplify to:

const concatenateStrings = (...strArr) => strArr.join('');

Not only is that simpler, but notice that it will work with any number of strings.


You want to do something similar. You have:

const sum = (x, y, z) => {
  const args = [x, y, z];
  // ...

You are getting in each argument and then manually putting them in an array. With the rest operator, you can do both in one step, like I did in the examples above. That is what the rest operator does - it takes a list of elements and puts them into an array.

Does that help?

1 Like

En este ejercicio tienes que pensar que todos los números son definidos como …args. Entonces, usaras lo que sabes hasta ahora para que todos los elementos sean tratados como una array.

const = sum(...args) => {
[...args]
}

Lo de arriba es una idea de como puedes modificar lo que se proporciona en el ejercicio para resolverlo.

Thanks, I finally understood