-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
51 lines (50 loc) · 1.07 KB
/
test.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
const messages = [
{
messageId: 6,
fromContact: "ziko",
messageContent: "i was asking about you man ",
sendTime: 6,
toContact: "admi",
},
{
messageId: 1,
fromContact: "admi",
messageContent: "hello mr ziko",
sendTime: 1,
toContact: "ziko",
},
{
messageId: 4,
fromContact: "admi",
messageContent: "i miss you bruh",
sendTime: 4,
toContact: "ziko",
},
{
messageId: 3,
fromContact: "ziko",
messageContent: "Yo admi",
sendTime: 3,
toContact: "admi",
},
{
messageId: 5,
fromContact: "ziko",
message_content: "me too my friend",
sendTime: 5,
toContact: "admi",
},
{
messageId: 2,
fromContact: "admi",
message_content: "how are you doing",
sendTime: 2,
toContact: "ziko",
},
];
const sorted = messages.sort((m1, m2) => {
if (m1.sendTime > m2.sendTime) return 1;
else if (m1.sendTime < m2.sendTime) return -1;
else return 0;
});
console.log(sorted);