forked from omiras/solved-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
champion-league-winners.js
48 lines (43 loc) · 1.92 KB
/
champion-league-winners.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
48
function countWins(winnerList, country) {
// your awesome code here
var contador = 0
winnerList.forEach(item => {
if (item.country == country)
contador = contador + 1;
})
return contador
}
/**
* Usando el método 'filter' https://www.w3schools.com/jsref/jsref_filter.asp
*
* function countWins(winnerList, country) {
// your awesome code here
let filtered = winnerList.filter(match => {
return match.country==country
})
return filtered.length
}
*/
const winnerList1 = [
{ season: '1996–97', team: 'Borussia Dortmund', country: 'Germany' },
{ season: '1997–98', team: 'Real Madrid', country: 'Spain' },
{ season: '1998–99', team: 'Manchester United', country: 'England' },
{ season: '1999–00', team: 'Real Madrid', country: 'Spain' },
{ season: '2000–01', team: 'Bayern Munich', country: 'Germany' },
{ season: '2001–02', team: 'Real Madrid', country: 'Spain' },
{ season: '2002–03', team: 'Milan', country: 'Italy' },
{ season: '2003–04', team: 'Porto', country: 'Portugal' },
{ season: '2004–05', team: 'Liverpool', country: 'England' },
{ season: '2005–06', team: 'Barcelona', country: 'Spain' },
{ season: '2006–07', team: 'Milan', country: 'Italy' },
{ season: '2007–08', team: 'Manchester United', country: 'England' },
{ season: '2008–09', team: 'Barcelona', country: 'Spain' },
{ season: '2009–10', team: 'Internazionale', country: 'Italy' },
{ season: '2010–11', team: 'Barcelona', country: 'Spain' },
{ season: '2011–12', team: 'Chelsea', country: 'England' },
{ season: '2012–13', team: 'Bayern', country: 'Germany' },
{ season: '2013–14', team: 'Real Madrid', country: 'Spain' },
{ season: '2014–15', team: 'Barcelona', country: 'Spain' },
{ season: '2015–16', team: 'Real Madrid', country: 'Spain' }
];
console.log(countWins(winnerList1, 'Portugal')) // Must be 1