-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp5.js
33 lines (21 loc) · 1.22 KB
/
fp5.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
// 1. create a constant named friends,
// which is an array that contains 2
// names of your choosing.
const friends = ['Ron', 'John'];
// 2. Create a new constant named updatedFriends,
// which includes the friends array values plus
// one additional name
const updatedFriends = [...friends, 'Robin'];
// 3. Create a new constant named friendNameLengths,
// which is based on the array updatedFriends,
// but instead of having the friends names,
// have the array store the length of each persons name.
const friendNameLengths = updatedFriends.map((friend) => friend.length)
// 4. Create a new constant named shorterNamedFriends,
// which will be a list of the friends except the friend with the longest name.
const shorterNamedFriendsWithMathMax = updatedFriends.filter((friend) => { return friend.length < Math.max(...friendNameLengths)})
const shorterNamedFriendsPureFp = updatedFriends.filter((friend) => { return friend.length < friendNameLengths.reduce((a, b) => { return a > b ? a : b; }) })
// 5. Print each variable to the console.
console.log(friends, updatedFriends, friendNameLengths, shorterNamedFriendsWithMathMax, shorterNamedFriendsPureFp)
// Solution can be seen at:
// https://jsbin.com/nevonet/1/edit?js,console