-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejercicio_3.js
111 lines (110 loc) · 5.23 KB
/
ejercicio_3.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//3. Create a function bmwSum that returns the sum of all prices of the BMW cars.
const cars = [
{ brand: "Mazda", price: 5241, model: 1989 },
{ brand: "Chevrolet", price: 4818, model: 1957 },
{ brand: "Toyota", price: 2074, model: 2009 },
{ brand: "Renault", price: 2395, model: 2012 },
{ brand: "Mercedes Benz", price: 6324, model: 1994 },
{ brand: "Renault", price: 4441, model: 1992 },
{ brand: "Chevrolet", price: 6923, model: 1995 },
{ brand: "Mercedes Benz", price: 4749, model: 1980 },
{ brand: "BMW", price: 6046, model: 2005 },
{ brand: "Toyota", price: 9630, model: 1970 },
{ brand: "Renault", price: 10568, model: 2009 },
{ brand: "Chevrolet", price: 9082, model: 2020 },
{ brand: "BMW", price: 10850, model: 1951 },
{ brand: "Mercedes Benz", price: 3267, model: 1998 },
{ brand: "BMW", price: 10897, model: 2014 },
{ brand: "Chevrolet", price: 3227, model: 1962 },
{ brand: "Mercedes Benz", price: 3498, model: 1970 },
{ brand: "Mazda", price: 4932, model: 1963 },
{ brand: "Chevrolet", price: 7187, model: 1975 },
{ brand: "Mercedes Benz", price: 7901, model: 1957 },
{ brand: "BMW", price: 6826, model: 1999 },
{ brand: "BMW", price: 10893, model: 1958 },
{ brand: "Renault", price: 5393, model: 2001 },
{ brand: "Ferrari", price: 10785, model: 1959 },
{ brand: "Mercedes Benz", price: 7028, model: 2017 },
{ brand: "BMW", price: 1423, model: 1978 },
{ brand: "Ferrari", price: 10408, model: 1954 },
{ brand: "Toyota", price: 4592, model: 1999 },
{ brand: "Toyota", price: 9441, model: 1960 },
{ brand: "Toyota", price: 6133, model: 1995 },
{ brand: "Mercedes Benz", price: 8188, model: 1960 },
{ brand: "Ferrari", price: 10588, model: 1986 },
{ brand: "BMW", price: 1631, model: 1969 },
{ brand: "Chevrolet", price: 10614, model: 1991 },
{ brand: "Chevrolet", price: 2289, model: 1960 },
{ brand: "Chevrolet", price: 2345, model: 1997 },
{ brand: "Toyota", price: 7713, model: 1987 },
{ brand: "Mazda", price: 4269, model: 2015 },
{ brand: "Mercedes Benz", price: 4152, model: 1983 },
{ brand: "Mazda", price: 4992, model: 2015 },
{ brand: "BMW", price: 4293, model: 1977 },
{ brand: "Renault", price: 10247, model: 1994 },
{ brand: "Mercedes Benz", price: 5219, model: 1967 },
{ brand: "Toyota", price: 10646, model: 2001 },
{ brand: "BMW", price: 2446, model: 1984 },
{ brand: "Mazda", price: 5397, model: 2001 },
{ brand: "Ferrari", price: 3700, model: 1998 },
{ brand: "Ferrari", price: 10897, model: 1965 },
{ brand: "BMW", price: 5642, model: 2012 },
{ brand: "Ferrari", price: 5305, model: 2006 },
{ brand: "Chevrolet", price: 8433, model: 1950 },
{ brand: "Mercedes Benz", price: 2560, model: 1952 },
{ brand: "Mazda", price: 8163, model: 1980 },
{ brand: "BMW", price: 9864, model: 1969 },
{ brand: "Toyota", price: 5823, model: 2003 },
{ brand: "Renault", price: 10355, model: 1961 },
{ brand: "Renault", price: 1910, model: 1971 },
{ brand: "Mazda", price: 10708, model: 2013 },
{ brand: "Ferrari", price: 3782, model: 1964 },
{ brand: "Toyota", price: 3155, model: 2010 },
{ brand: "Ferrari", price: 5476, model: 1970 },
{ brand: "Mercedes Benz", price: 6694, model: 1950 },
{ brand: "Ferrari", price: 4021, model: 2000 },
{ brand: "Toyota", price: 4070, model: 2014 },
{ brand: "Chevrolet", price: 8979, model: 1955 },
{ brand: "Mercedes Benz", price: 7918, model: 2001 },
{ brand: "Chevrolet", price: 3338, model: 2004 },
{ brand: "Mercedes Benz", price: 5013, model: 1985 },
{ brand: "BMW", price: 6187, model: 1957 },
{ brand: "Mercedes Benz", price: 9180, model: 1956 },
{ brand: "Renault", price: 7404, model: 1965 },
{ brand: "Toyota", price: 10900, model: 2009 },
{ brand: "Renault", price: 3401, model: 1967 },
{ brand: "Renault", price: 7991, model: 1958 },
{ brand: "BMW", price: 9680, model: 1956 },
{ brand: "Toyota", price: 5345, model: 1982 },
{ brand: "Renault", price: 1808, model: 1960 },
{ brand: "BMW", price: 1225, model: 1962 },
{ brand: "Toyota", price: 7099, model: 1984 },
{ brand: "Mercedes Benz", price: 2425, model: 1971 },
{ brand: "Ferrari", price: 8509, model: 1985 },
{ brand: "Mercedes Benz", price: 3884, model: 1982 },
{ brand: "BMW", price: 6882, model: 1974 },
{ brand: "Mercedes Benz", price: 10794, model: 1974 },
{ brand: "Chevrolet", price: 9937, model: 1979 },
{ brand: "BMW", price: 1849, model: 1989 },
{ brand: "BMW", price: 5715, model: 1982 },
{ brand: "Ferrari", price: 5938, model: 1950 },
{ brand: "BMW", price: 3353, model: 1999 },
{ brand: "Chevrolet", price: 10527, model: 1951 },
{ brand: "Chevrolet", price: 1577, model: 1951 },
{ brand: "Renault", price: 5029, model: 1985 },
{ brand: "Toyota", price: 7809, model: 1973 },
{ brand: "Toyota", price: 7808, model: 1999 },
{ brand: "Toyota", price: 4444, model: 2001 },
{ brand: "Renault", price: 4511, model: 1957 },
{ brand: "Ferrari", price: 4462, model: 1991 },
{ brand: "BMW", price: 8753, model: 2011 },
{ brand: "Chevrolet", price: 4726, model: 1974 },
{ brand: "Ferrari", price: 9541, model: 1970 },
];
function bmwSum(cars) {
return cars
.filter((car) => car.brand === "BMW")
.map((car) => car.price)
.reduce((acc, prev) => acc + prev, 0);
}
console.log(` Todos los BMW juntos cuestan $${bmwSum(cars)}`);