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

115
Vistas
Javascript sort by multiple categories

I need to make a sort by Status and ETA, I've managed to make the sort by Status by can't figure out to make it also by ETA. What I've done so far is only sorting by Status, it should sort by ETA also, but I can't manage to figure out why this solution is not working.

Here is my code:

const data = [
        {
          id: 1,
          name: "Delivery 1",
          amount: 3,
          status: "active",
          eta: 15
        },
        {
          id: 2,
          name: "Delivery 2",
          amount: 5,
          status: "pending"
        },
        {
          id: 3,
          name: "Delivery 3",
          amount: 3,
          status: "active",
          eta: 10
        },
        {
          id: 4,
          name: "Delivery 4",
          amount: 4,
          status: "upcoming"
        },
        {
          id: 5,
          name: "Delivery 5",
          amount: 3,
          status: "active",
          eta: 25
        },
        {
          id: 6,
          name: "Delivery 6",
          amount: 3,
          status: "active",
          eta: 5
        }
      ];

<tbody>
  {searchResults.sort((a, b) => a.eta > b.eta ? 1 : -1 && statusOrdered.indexOf(a.status) - statusOrdered.indexOf(b.status)).map(el => {
    return (
    <tr>
      <td>{el.id}</td>
      <td>{el.name}</td>
      <td>{el.amount}</td>
      <td>{el.eta}</td>
      <td>{el.status}</td>
    </tr> 
    );
  })}
  </tbody>
    </table>
  );
};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just to explain you how it will look like, consider the following example.

(a.eta - b.eta) || (a.status - b.status)

So you need to use || instead of &&.

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