Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!