Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
.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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda