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

146
Views
how to create a function that takes ANY number and finds the LARGEST number formed by consecutive digits in that number

how to create a function that takes ANY number and finds the LARGEST number formed by consecutive digits in that number in Javascript ?

example: input: 90123609789 output: 90123

input: 53590 output 90 input:674030098567819 output: 5678

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try all substrings where the difference between adjacent digits is 1 under modulus 10.

function largestConsecutiveDigits(n) {
  let str = String(n),
    res = Math.max(...str);
  for (let i = 0; i < str.length; i++) {
    for (let j = i + 1; j < str.length; j++) {
      if ((str[j] - str[j - 1] + 10) % 10 === 1) 
        res = Math.max(res, str.slice(i, j + 1));
      else break;
    }
  }
  return res;
}
console.log(largestConsecutiveDigits('90123609789'));
console.log(largestConsecutiveDigits('53590'));

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!