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

148
Vistas
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 Respuestas
Responde la pregunta

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 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