-
Notifications
You must be signed in to change notification settings - Fork 0
/
date-test.ts
59 lines (57 loc) · 1022 Bytes
/
date-test.ts
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
interface IEvent {
id: number
name: string
startDate: string
endDate: string | null
}
const events: IEvent[] = [
{
id: 10001,
name: "Today event",
startDate: "2021-04-08",
endDate: null,
},
{
id: 10002,
name: "Andreas",
startDate: "1988-08-25",
endDate: null,
},
{
id: 10010,
name: "Testar med endast år",
startDate: "1975-05",
endDate: null,
},
{
id: 10003,
name: "Jasmin",
startDate: "1986-02-15",
endDate: null,
},
{
id: 10004,
name: "Joakim",
startDate: "1991-04-15",
endDate: null,
},
{
id: 10013,
name: "Farfar",
startDate: "1975",
endDate: null,
},
{
id: 10005,
name: "Last days",
startDate: "1914-10-91",
endDate: null,
},
]
const newArr = events
.map(({ name, startDate, id }) => {
return { name, id, startDate }
})
.sort((a, b) => (a.startDate > b.startDate ? 1 : a.startDate < b.startDate ? -1 : 0))
.map((event) => event.name)
console.log(newArr)