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

388
Vistas
Printing consecutive numbers, can't modify function

I've been in some technical interviews, this one got me frustrated as I can't modify the existent function and need to print 5 consecutive numbers (Number: 1, Number: 2, Number: 3....) plus the Promise

console.log('Logging Num 1');
const printNumber = (number) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(`Number: ${number}`);
      resolve();
    }, Math.floor(Math.random() * 10));
  });
};

printNumber(1);
printNumber(2);

This was the hint, I remembered this one for looping through elements

for(let i = 1; i <= 5; i+= 1) 

But how can I add this in the code without modifying the function? Yes I got nervous and confused.

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

0

You should be able to do this

const syncLog = async (x) => {
    for(let i = 0; i < x; i++){
        await printNumber(i)
    }
}

syncLog(5)

>> Number: 0
>> Number: 1
>> Number: 2
>> Number: 3
>> Number: 4
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