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

224
Views
traverse (iterate) each element of array in specific time?

I have an array which have 200 elements like -100 to 100. I want to traverse or iterate this whole array in a specific time duration. for example I want to traverse or iterate this array in 5 second or also in 1 minutes. it's depend on user that , in how much time is define for traverse this whole array. How can i do it?

const array = [-100,-99,-98....0....98,99,100];

function traverseArr(){
....

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

0

You could take a function for the interval and calculate the duration for each element.

function traverseArray(array, time, fn) {
    let i = 0;
    const handle = setInterval(() => {
        if (i < array.length) fn(array[i++]);
        else clearInterval(handle);
    }, time / array.length);

}

traverseArray([5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5], 10000, v => console.log(new Date().toISOString(), v));
.as-console-wrapper { max-height: 100% !important; top: 0; }

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!