my array consists of 6 elements out of which as on date 4 are empty or 0 because previous month data comes next month as under:
July-12 Aug-12 Sep-12 Oct-12 nov-12 Dec-12
the data for the sep is availabel on 31st oct and so on.
i wanted to calculate the average every month of the available data.
so I wrote the follwing code in js.
if i populate the empty data 0 ,as on date the average comes to 71 instead 213 because the array length is 6 instead of 2 required to be used for correct results.
var indxnos = new Array(6)
var Sum = 0
for (var i = 0; i < indxnos.length; i++)
Average = Sum/indxnos.length
Math.round(Average) document.DA_Slabs.avg.value= Average
I am new to JS and arrays so I donot know how to reduce the length of the array while calculating average every month till the half year.I have taken the array as 6 as an example although the data that is required to be used is for more than 5 years. It seems easy to divide by 2 and proceed so on but in actual case the array consists of about 60 months and so I need help.
Further advise me to further clean or shorten my code
so that every month I get the correct average.