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

121
Views
Cómo ordenar una matriz principalmente con los primeros elementos y luego, si son iguales, luego con los segundos elementos. Entonces el eje xy en orden ascendente

¿Cómo clasifico la matriz para que esta salida

 [ [ '6.9', '14.5' ], [ '22.2', '28.9' ] ]

se ordena principalmente con el valor x, por lo que 6,9 y 22,5 en el ejemplo anterior y, en segundo lugar, con el eje y, 14,5 y 28,9 en el ejemplo anterior.

este es mi código actualmente para obtener el resultado.

 const mySet = uniqueArray4(x_y_total); mySet.forEach(element => { let sumx = 0, sumy = 0; for(let i = 0; i < element.length; i++) { sumx += element[i][0]/element.length; sumy += element[i][1]/element.length; } answer.push([sumy.toFixed(1), sumx.toFixed(1)]); }); answer.forEach(element => { finalanswer.push(element); })

Bastante nuevo en js, busqué en Google pero ha sido bastante difícil saber cómo debo implementar esto.

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

0

Puede ordenar en función de la primera entrada y luego de la segunda entrada, algo así como:

 // Sorting on 1st param answer.sort((a,b) => a[0] - b[0]); // Sorting on 2nd param given then 1st param is sorted, if not, return 0 answer.sort((a,b) => a[0] < b[0] ? a[1] - b[1] : 0);
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!