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

283
Vistas
Cant stop the flow of a loop | Javascript

Im trying return an int that count the last Zeros of an int, but I can´t to stop the flow of the loop when it finds something that is not zero. whats wrong?

const endZeros = (value) => {
  const stringValue = `${value}`
  const arrValue = stringValue.split("").reverse()
  let total = 0;
  arrValue.map(el => {
    if (el === "0") {
      total = total + 1
    } else {
      return // I check return false too (and true, and all! --> desesperation)
    }
  })
  return total;
}

endZeros(100100)

Thank You, everyone ❤️

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

How about a simple regexp?

const lastZeros = num => { const zeros = String(num).match(/0+$/); return zeros ? zeros[0].length : 0 };

console.log(lastZeros(100100))
console.log(lastZeros(111111))
console.log(lastZeros(101000))

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