average

add and derive average using javascript and structures

Swiftlikeninja's picture

Let me start off by saying that I am a complete noob when it comes to javascript. Id imagine that this should be easy to accomplish.

I would like to know how to take a structure and add up all the values then divide the total by the structure count providing me with an average. Currently I am accomplishing this with a rather ugly and lengthy set of structure makers to a math patch but its not dynamic, and is pretty sloppy. To go one step further I would like to be able to add up all of a certain sub index within a complete structure through javascript. Im not concerned with maintaining the original structure, the only output needed is the average value.

Im not asking anyone to make this for me but again im lost when it comes to javascript and would appreciate any assistance. Ive dugged through the post to attempt to find an answer got nowhere. Ive checked cybero's reference site but cant figure out what to combine to achieve what I need.