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

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

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