# Multiple computation in array of data Edit Subject

I have a table of scores, I want to get the total scores per Contestant and per Criteria. Any body knows the server code of these scores? Please help. Please see the target output below. Thank you.

TABLE
Score Contestant Criteria Judges
30 Contestant #1 Confident Judge #1
15 Contestant #1 Costume Judge #1
40 Contestant #1 Talent Judge #1
28 Contestant #1 Confident Judge #2
12 Contestant #1 Costume Judge #2
40 Contestant #1 Talent Judge #2

34 Contestant #2 Confident Judge #1
20 Contestant #2 Costume Judge #1
44 Contestant #2 Talent Judge #1
33 Contestant #2 Confident Judge #2
19 Contestant #2 Costume Judge #2
44 Contestant #2 Talent Judge #2

35 Contestant #3 Confident Judge #1
18 Contestant #3 Costume Judge #1
42 Contestant #3 Talent Judge #1
32 Contestant #3 Confident Judge #2
20 Contestant #3 Costume Judge #2
45 Contestant #3 Talent Judge #2

Confident = (sum of same criterias [2] ) / number of judges [2]
Costume = (sum of same criterias [2]) / number of judges [2]
Talent = (sum of same criterias [2]) / number of judges [2]
Total = Confident + Costume + Talent

FINAL OUTPUT
Contestant Name Confident Costume Talent Total
Contestant #1 29 13.5 40 82.5
Contestant #2
Contestant #3
1 person has
this question
This topic is no longer open for comments or replies.
• Hi,

Is this data stored in Database? Yes, you can get all the data from table, and then sum all column elements:
```var arr = [1,2,3,5];
var sum = 0;
arr.forEach(function(element) {
sum+=element;
});```
How does this make you feel?
I'm
• Hi Katya,

I got unexpected token error, please see my code below

var DB_id='53903445e4b0889b402e6c81',
collectionName='tblScore',
columnName = 'numScore',
competitionId = request.get("competition");

var params = {}; //Define parameters object
params.criteria = { //Query criteria:
"charCompetition": {"\$inQuery" : {"charCompetition":competitionId}}
};

try {
query = Collection.query(DB_id, collectionName, params);

var arr = query;
var sum = 0;
arr.forEach(query(element) {
sum+=element;
}
}
response.success({totalSum: sum + "%"}, "application/json");
} catch (e) {
response.success({message: e.message, code: e.code}, "application/json");
}
How does this make you feel?
I'm
• Hello Lonlon ,

First, you need to use

`arr.forEach(function(element)`

not

`arr.forEach(query(element)`

And, secondly, you need to summarize some specific property from an entry, i.e.:

```arr.forEach(function(element) { sum+=parseInt (element ["someProperty"]); }```
How does this make you feel?