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

106
Views
Tengo 3 valores de entrada y estoy tratando de ordenarlos por tamaño y agregarlos con js

Tengo un formulario con 3 valores de entrada y estoy tratando de ordenarlos de menor a mayor y luego hacer esto.

  1. Suma los 2 lados más cortos: 40 + 50 = 90.
  2. Multiplica este número por 2: 90 x 2 = 180.
  3. Agregue la longitud más larga a este número: 180 + 55 = 235.

Los ordené y los puse en la matriz de entradas, pero no puedo entender cómo agregarlos y multiplicarlos 😓.

Cualquier ayuda o sugerencia chicos.

 <form class="calc__container"> <input data-input type="number" id="length" placeholder="Length"> <input data-input type="number" id="width" placeholder="Width"> <input data-input type="number" id="hight" placeholder="Higth"> <button class="submit__btn hover">Submit</button> <div class="ans-container"> <p class="ans__p ">271 cm</p> </div> </form> let lInput = document.getElementById('length'); let wInput = document.getElementById('width'); let hInput = document.getElementById('hight'); const submitBtn = document.querySelector('.submit__btn') let inputs = [] submitBtn.addEventListener('click', function (e) { e.preventDefault(); let allpointsArr = [ Number(lInput.value), Number(wInput.value), Number(hInput.value) ]; allpointsArr.sort(function(a, b){return a - b}); points.push(allpointsArr) console.log(points); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

en javascript sort está diseñado para ordenar matrices de valores de cadena, no matrices de números.

mejora tu clasificación aquí prueba esto:

 const points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){return a - b});

puedes consultar desde este enlace

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!