I have like 40 different arrays and I want to find the average value of each of them.
In order to do it with each one, I have this code:
var SumArray1 = 0;
var avgArray1 = 0;
$.each(array1,function() {
SumArray1 += this;
avgArray1 = (SumArray1)/(array1.length);
});
But as I have those 40 arrays, I was trying to look for a way to make that function abstract, but I don’t know how to introduce parameters for a function using $.each and I don’t think having forty functions would be the right thing to do…
Thanks!
Add this code:
Then at any point you can do something like