Skip to content

Commit 382871a

Browse files
committed
특이한 정렬 / 기초
1 parent 031464f commit 382871a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function solution(numlist, n) {
2+
let queue = [...numlist];
3+
let result = [];
4+
5+
queue.sort((a, b) => {
6+
const A = Math.abs(n - a);
7+
const B = Math.abs(n - b);
8+
if(A === B) {
9+
return b - a;
10+
}
11+
return A - B;
12+
});
13+
14+
while(queue.length > 0) {
15+
result.push(queue.shift());
16+
}
17+
18+
return result;
19+
}

0 commit comments

Comments
 (0)