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

156
Visualizações
How to implement bubble sort to sort string length from largest to smallest?

How to implement bubble sort to sort string length from largest to smallest?

I tried this but it is sorted from smallest to largest

function order(array) {

  for ( let i = 0 ; i < array.length ; i++ ) {
    for ( let j = i ; j < array.length ; j++ ) {

      if ( array[i].length < array[j].length ) {
        let temp = array[i];
        array[i] = array[j];
        array[j] = temp;
      }

    }
  }

  return array;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Well... if this comparison

if ( array[i].length < array[j].length ) {
  /* swap */
}

sorts in ascending order...

What comparison might sort in descending order?

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