-
Notifications
You must be signed in to change notification settings - Fork 0
/
gold_ball.js
47 lines (35 loc) · 983 Bytes
/
gold_ball.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// A program for calculation the utility and performance of players based on their statistics
var firstPlayer = {
name: 'Messi',
goals: 0,
passes: 0
}
var secondPlayer = {
name: 'Zidan',
goals: 0,
passes: 0
}
var thirdPlayer = {
name: 'Ronaldo',
goals: 0,
passes: 0
}
var soccerPlayers = [firstPlayer, secondPlayer, thirdPlayer];
var sumGoals = 0;
var getStatistics = function (players) {
for (var i = 0; i < players.length; i++) {
var coefficient = players[i].goals * 2 + players[i].passes;
players[i] ['coefficient'] = coefficient;
sumGoals += players[i].goals;
console.log('sumGoals ' + sumGoals);
}
for (var i = 0; i < players.length; i++) {
var percent = (players[i].goals / sumGoals) * 100;
percent = Math.round(percent);
console.log('percent ' + percent);
players[i] ['percent'] = percent;
}
return players;
};
soccerPlayers = getStatistics(soccerPlayers);
console.log(soccerPlayers);