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

125
Visualizações
Using flatMap and Math.max to get a certain field's highest value from obj

I am currently working with an object and trying to extract the highest value of duration field. I am trying to use both flatMap and Math.max to achieve this but so far I am getting a -Infinity result. I am also calling this flatMap twice which is likely not right :/. What would be the right approach to get the highest value of duration?

const users = [{
        name: 'User1',
        configuration: [{
                email: 'test1@email.com',
                duration: 60,
                active: true
            },
            {
                email: 'test2@email.com',
                duration: 180,
                active: false
            }
        ],
    },
    {
        name: 'User2',
        configuration: [{
                email: 'test3@email.com',
                duration: 120,
                active: true
            },
            {
                email: 'test4@email.com',
                duration: 30,
                active: true
            }
        ],
    },
    {
        name: 'User3',
        configuration: [{
                email: 'test5@email.com',
                duration: 300,
                active: true
            },
            {
                email: 'test6@email.com',
                duration: 10,
                active: true
            }
        ],
    },
];

Code:

const x = users.flatMap(user => user.configuration);
const y = x.flatMap(user => user.duration);
const highestvalue = Math.max(...Object.values(y).flat().flatMap(Object.values));
console.log(highestvalue);

Current Result:

-Infinity

Desired Result:

300
over 4 years ago · Santiago Trujillo
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