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

151
Views
Suma sin número mayor y menor

He pasado algunas horas tratando de entender dónde está el error en este código. La depuración indicó que la salida es 0 como debería ser para cualquier número menor que 0. Sin embargo, este código aún no puede pasar la prueba:

 function sumArray(array) { return array < 1 || array == null ? 0 :array.reduce((a, b) => a + b) - Math.max(...array) - Math.min(...array); } console.log(sumArray([-3]))
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

function sumValues (array) { if (array != null && array.length > 0) { let min = Math.min(...array); // lowest in array by spreading let max = Math.max(...array); // highest in array by spreading // Sum up the numbers in the array let sum = array.reduce((acc, val) => acc + val, 0); // Do the math let result = sum - max - min; if (result > 0) { return result } else { return 0 } } else { return 0 } } console.log(sumValues([1,2,3,4,5,6]))
about 4 years ago · Santiago Gelvez Report

0

Definitivamente mejor:

 function sumArray(array) { if (array == null || array.length <= 1) { return 0 } var max = Math.max(...array); var min = Math.min(...array); var sum = 0 for (i = 0; i < array.length; i++) { sum += array[i]; } return sum - max - min }
about 4 years ago · Santiago Gelvez 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!