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 Find the maximum number in a jagged array given below array of numbers?

how to Find the maximum number in a jagged array given below array of numbers?

const array= [2,4,10,[12,4,[100,99],4],[3,2,99],0];
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

If you know the maximum depth of nesting, then you can flat the array and find the maximum:

Math.max(...array.flat(depth));

If you don't know the maximum depth, you need to iterate over all the items recursively:

const findMax = item => Math.max(...item.map(row => Array.isArray(row) ? findMax(row) : row));

console.log(findMax([2,4,10,[12,4,[100,99],4],[3,2,99],0]));

about 4 years ago · Juan Pablo Isaza Relatório

0

You can flat the jagged array using flat method and after that find max in it. like:

const array = [2,4,10,[12,4,[100,99],4],[3,2,99],0];
const flatArray = array.flat(2);
console.log("Max Value is "+ Math.max(...flatArray));
about 4 years ago · Juan Pablo Isaza Relatório

0

if you don't know the level of depth

let array = [2, 4, 10, [12, 4, [100, 99], 4], [3, 2, 99], 0 ]

let max = 0

function maxNumber(array) {
  for (let i = 0; i < array.length; i++) {
    if (Array.isArray(array[i])) {
      maxNumber(array[i])
    } else {
      if (array[i] > max) {
        max = array[i]
      }
    }
  }
}
maxNumber(array)
console.log(max)

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