-
Notifications
You must be signed in to change notification settings - Fork 10
0에서 23 순으로 오름차순을 4~...24...~3으로 변경하는 로직
Park Sang Shin edited this page Jan 22, 2021
·
2 revisions
const getBiasHour = (recode: ITimeRecode, bias: number = 4) => {
const biasHour = recode.startTime.hour - bias;
if (biasHour < 0) {
return biasHour + 24;
}
return biasHour;
};
const sortByStartTime = (recode1:ITimeRecode, recode2: ITimeRecode) => {
const startTimeDiff = getBiasHour(recode1) - getBiasHour(recode2);
if (startTimeDiff === 0) {
return (recode1.startTime.min - recode2.startTime.min);
}
return startTimeDiff;
};
0,1,2,3 을 가장 뒤로 보내고 싶기 때문에 값을 가장 크게 만들어 주면 된다.
각 시간에 4를 빼면 -4, -3, -2, -1 ... 이 되는데 여기에 24를 더해주면
origin : 0 1 2 3 4 5 6 7
new : 20, 21, 22, 23, 0, 1, 2, 3, ..
정렬하게되면 origin의 위치
4, 5, 6, 7, 8, ... 0, 1, 2, 3
이 된다.