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

93
Views
Create loop, which adds up 72 elements of a 2016 element array and stores the sum in an element in a new array

At the moment it always takes the same 72 elements. How can I manage that after each round it takes the next 72 values e.g. 73 - 144 than 145 - 217 etc.?

    var houseconsumtion_week = new Array();
    var i = 0;
    var sum = 0;
    
    // should loop 28 times, houseconsumtion.length = Array containing 2016 elements
    for (var j = 0; j < houseconsumtion.length; j+=72) {
        for (var i = 0; i < 72; i++) {
            sum += houseconsumtion[i];
        }
        houseconsumtion_week.push(sum);
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can access the element at index i + j each time.

for (var j = 0; j < houseconsumtion.length; j += 72) {
    for (var i = 0; i < 72; i++) {
        sum += houseconsumtion[i + j];
    }
    houseconsumtion_week.push(sum);
}
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!