C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# find average of an array of objects

By : Cynthia Gonzales
Date : November 20 2020, 07:00 PM
I wish this helpful for you You can filter out "females" to a new array, and then reduce that down to a total of all ages, then use the length of the females array to divide the total by:
code :
``````const people = [{name:'Sarah', gender:'female', age:25}, {name:'Tom', gender:'male', age:18}, {name:'Tim', gender:'male', age:65}, {name:'Kim', gender:'female', age:58}];

const females = people.filter(person => person.gender === 'female');

const average = females.reduce((total, next) => total + next.age, 0) / females.length;

console.log(average);``````

Share :

## Find average of array using only average of 2 members at a time

By : Ankur Bakshi
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Seems like you could use mergesort-esque logic here...
If you have cups 1,2,3,4,5,6,7,8...

## Get average value from array consisting of objects based on objects fields

By : thelord
Date : March 29 2020, 07:55 AM
will be helpful for those in need I have a document of the following structure: , You can use \$map to with \$avg to output avg in 3.2 mongo version.
code :
``````db.col_name.aggregate(
[{"\$project":{
"avgMetrics":{
"\$avg":{
"\$map":{
"input":"\$powerMetrics",
"as":"val",
"in":{"\$divide":["\$\$val.powerConsumption","\$\$val.duration"]}
}
}
}
}}])
``````

## Find Average using Array of Objects/Object Array

By : Charan Kumar
Date : March 29 2020, 07:55 AM
may help you . Your approach is wrong. Your Height class appears to be responsible for the evaluation of the mean value. Hence, you should put all values inside a single Height instance, instead of generating a new instance for each user value.
However, h is an array of Heights object, while print() method is defined on a single Height instance. In order to call such method, you have to access one of the objects contained in h, that is h[0].print().

## MongoDB Find the average value from arrays of objects

By : nanobot
Date : March 29 2020, 07:55 AM
Hope this helps This aggregation job will return average of mathematics marks throughout the collection
code :
``````db.collection.aggregate([
{
\$unwind: "\$group.syllabus.subjects"
},
{
\$match: {
"group.syllabus.subjects.titel_of_sub": "Mathematics"
}
},
{
\$group: {
_id: null,
avg_math_marks: {
\$avg: "\$group.syllabus.subjects.mark"
}
}
}
])
``````

## LINQ find average from CSV objects

By : Shoeb
Date : March 29 2020, 07:55 AM
Hope this helps I have a CSV with stock info in it (that I have a list of DailyValues objects called stockValues) that I need to pull from. It looks like this: , Can you try something like: