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

251
Vistas
JavaScript: How do I sort times in a nested array?

I'm working with a JSON file that contains the 2021 NFL schedule. I'm able to easily filter out Thursday, Sunday & Monday games. The filtering method returns my Sunday games in an array of objects.

Below is a look at how my Sunday array is set up. This code just shows the first two weeks for the Packers, but there are 18 weeks in the schedule, and I have the same info for each team.

So for the first week, for example, I'll have an array of 14 games. (The 14 teams are the visiting teams.) I need to loop through the games for the desired week and sort the array by the time of the games. A typical Sunday will have games at 12:00 PM, 3:25 PM, and 7:15 PM. There are other starting times throughout the season.

[
    {
      "name": "Green Bay Packers",
      "id": 1,
      "nickname": "Packers",
      "homefield": "Lambeau Field",
      "division": "NFC North",
      "schedule": [
        {
          "week": "1",
          "date": "Sept. 12",
          "weekday": "Sunday",
          "time": "3:25 PM",
          "network": "Fox",
          "opponent": "New Orleans Saints",
          "homeAway": "away",
          "venue": "Mercedes-Benz Superdome"
        },
        {
          "week": "2",
          "date": "Sept. 19",
          "weekday": "Monday",
          "time": "7:15 PM",
          "network": "ESPN",
          "opponent": "Detroit Lions",
          "homeAway": "home",
          "venue": "Lambeau Field"
        },
    etc.

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

0

Figured it out. "su" is my array of Sunday games, so I pass that and the week number into my function.

function sortSundayByTime(su, weekNo) {
  su.sort((a, b) => {
    if (a.schedule[weekNo].time < b.schedule[weekNo].time) {
      return -1;
    } else if (a.schedule[weekNo].time > b.schedule[weekNo].time) {
      return 1;
    }
  });
}
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