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

154
Views
¿Por qué mi matriz (basada en el tiempo) no está ordenada por orden de ascendencia?

tengo este guion aqui

 let myVar = [{time: "3:00 pm", name: "Landon"},{time: "5:20 pm", name: "Amanda"},{time: "4:00 pm", name: "Kid"}] const sortedArray = myVar.sort((a,b) => new moment(a.time).format('hh:mm a') - new moment(b.time).format('hh:mm a')) console.log(sortedArray)

La idea es que ordenemos la matriz por tiempo. Pero no funciona y no estoy seguro de por qué.

Cada búsqueda en Google me lleva a respuestas como esta: https://gist.github.com/onildoaguiar/6cf7dbf9e0f0b8684eb5b0977b40c5ad

Pero no funciona para mí.

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

0

Su código pasa un formato en el momento equivocado. Debe especificar el formato de entrada , no el formato de salida .

Así que cambia a:

 let myVar = [{time: "3:00 pm", name: "Landon"},{time: "5:20 pm", name: "Amanda"},{time: "4:00 pm", name: "Kid"}] const sortedArray = myVar.sort((a,b) => new moment(a.time, 'hh:mm a') - new moment(b.time, 'hh:mm a')) console.log(sortedArray)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js" ></script>

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!