-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
41 lines (39 loc) · 938 Bytes
/
utils.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
function getDateFormBithday(bday) {
if(!bday){
return null;
}
const [day,month] = bday.split(".");
const date = new Date();
date.setMonth(month-1);
date.setDate(day);
return date;
}
function getNameForCompare(friend) {
let name='';
if (friend.first_name){
name+=friend.first_name;
}
if (friend.last_name){
name+=friend.last_name;
}
return name;
}
export function sortByBDay(list) {
return list.sort((a, b)=>{
if(!a.bdate){
return 1;
}else if (!b.bdate){
return -1;
}
const aDate = getDateFormBithday(a.bdate);
const bDate= getDateFormBithday(b.bdate);
return aDate-bDate;
});
}
export function sortByName(list) {
return list.sort((a,b)=>{
const aName = getNameForCompare(a);
const bName = getNameForCompare(b);
return aName.localeCompare(bName);
});
}