-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.js
36 lines (28 loc) · 859 Bytes
/
test3.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
// create a function getMostFavoriteSport
// that has one parameter, getMostFavoriteSport return sport
// that has like score greater than 5
// using filter
const sports = [
{
name: 'basketball',
like: 6
},
{
name: 'swim',
like: 5
},
{
name: 'football',
like: 10
},
]
// ======================================= first method < Basic > ======================================
function getMostFavoriteSport(x) {
return x.filter(function (y) {
return y.like > 5;
})
}
// ====================================== second method < using arrow function > =========================
var getMostFavoriteSport = (x) => x.filter (y => y.like >5);
console.log(getMostFavoriteSport(sports))
// Output: [{ name: 'basketball, like: 6 }, { name: 'football, like: 10 }]