Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
.sort not sorting from lowest to highest
while (true) {
  let texts = await page.evaluate(() => {
    let data = [];
    let elements = document.getElementsByClassName("my-2 card__price tw-truncate");
    for (var element of elements) {

      var floor = Number(element.textContent.split("SOL")[0])
      data.push(floor)
    }

    return data.sort()
  });
  floorpricearray = texts
  if (texts !== undefined) {

    console.log(floorpricearray)
  }
}

The output

[
      10,   11,    5.3,    5.3,
    5.38,  5.4,    5.4, 5.4321,
  5.4321,  5.5, 5.6942,    5.8,
    5.95,  6.2,      7,   7.95,
    7.99, 8.05,    8.3,      9
]
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need to give the native .sort method a comparator function like so, otherwise the values will converted to strings and then sorted by the characters ASCII value.

data.sort((a, b) => {
  return a - b;
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try this

var a = [10, 11, 5.3, 5.3,
  5.38, 5.4, 5.4, 5.4321,
  5.4321, 5.5, 5.6942, 5.8,
  5.95, 6.2, 7, 7.95,
  7.99, 8.05, 8.3, 9
];
a.sort(function(a, b) {
  return a - b;
});
alert(a);

about 4 years ago · Juan Pablo Isaza Denunciar

0

It is sorting the array considering the array elements as string. To get it sorted from lowest to highest it needs to be a number.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda