-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask25.js
24 lines (23 loc) · 859 Bytes
/
task25.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
//Total amount of points
/*Our football team has finished the championship.
Our team's match results are recorded in a collection of strings. Each match is represented by a string in the format "x:y", where x is our team's score and y is our opponents score.
For example: ["3:1", "2:2", "0:1", ...]
Points are awarded for each match as follows:
if x > y: 3 points (win)
if x < y: 0 points (loss)
if x = y: 1 point (tie)
We need to write a function that takes this collection and returns the number of points our team (x) got in the championship by the rules given above.
*/
function points(games) {
let res = 0;
for (let i = 0; i < games.length; i++) {
if (games[i][0] > games[i][2]) {
res += 3;
} else if (games[i][0] < games[i][2]) {
continue;
} else if (games[i][0] === games[i][2]) {
res += 1;
}
}
return res;
}