-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 11
62 lines (50 loc) · 1.37 KB
/
Day 11
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
DAY 11
Instructions
(This challenge is worth 10 points)
Your task is to write a function that will take in a list of platforms and a date as a string. That function will update the date property on the first platform with an empty date and then return the platform list.
In other terms, for each platform of the platform list array, update the date of the first free one and then return the updated platform list.
Examples
Input:
const missionDate = "2021-12-12"
const platformList = [
{
name:"Platform A",
bookDate:"2021-12-11"
},
{
name:"Platform B",
bookDate:undefined
},
{
name:"Platform C",
bookDate:undefined
},
]
Output:
const platformList = [
{
name:"Platform A",
bookDate:"2021-12-11"
},
{
name:"Platform B",
bookDate:"2021-12-12"
},
{
name:"Platform C",
bookDate:undefined
},
]
SOLUTION
function bookFreePlatform (platformList, missionDate){
//itirating through the platforList array
for (let i in platformList){
//when undefined bookDate found...
if (platformList[i].bookDate === undefined){
//...setting the bookDate to the missioDate
platformList[i].bookDate = missionDate
//returning updated platformList
return platformList
}
}
}