Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:15:39+00:00 2026-06-17T09:15:39+00:00

I have like 40 different arrays and I want to find the average value

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:15:40+00:00Added an answer on June 17, 2026 at 9:15 am

    Add this code:

    Array.prototype.average = function() {
        var s = 0;
        for(var i = 0; i < this.length; ++i) {
            s += this[i];
        }
        return s/this.length;
    }
    

    Then at any point you can do something like

    var myArray = [1,2,3,4];
    var calculatedAverage = myArray.average();  // This will equal 2.5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of different times that looks like this: 20120628061533.0, 20120628064851.0, 20120628064853.0,
I want to have different layouts like [left|content|right] and [left|content] or [content|right] when using
If I have three different tables like this table_1 Field 1: victories Field 2:
I have 5 different arrays for a bunch of excercises, like so: const oef1:Array
I have a section of code like this: while (scanFile.hasNextLine()) { String currentLine =
I have 2 arrays (both containing 2 strings each) one contains serial numbers from
I have a plist dictionary with several arrays where each have different number of
I have created like a design studio and it has different functionalities like drag
I would like to have different applications under the same domain using Heroku. Because
I would like to have two different log4j loggers in my application, and for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.