Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
¿Puedo pasar un parámetro diferente en lugar de (n1, n2, n3)?

Escriba una función llamada sumArray que acepte un solo argumento: una matriz de números. Debería devolver la suma de todos los números en la matriz.

Condición:

  1. Necesitará una variable para realizar un seguimiento del total. Debe comenzar como cero.

  2. Recorra la matriz para cada elemento, agréguelo a la variable total.

 function sumArray(n1, n2, n3) { let total = n1 + n2 + n3; return total; } sumArray([3,45,66]);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente haga un bucle desde la matriz y obtenga la salida

 function sumArray(arr){ let total = 0; arr.forEach((i) => total+=i); return total; } console.log(sumArray([3,45,66]));

O puedes probar con reduce como explica Cristian

 function sumArray(arr){ const reducer = (previousValue, currentValue) => previousValue + currentValue; let total = arr.reduce(reducer) return total; } console.log(sumArray([3,45,66]));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!