Skip to content

Commit 18292f3

Browse files
author
Eric
committed
86차 3번 문제풀이(참고)
1 parent b12fe77 commit 18292f3

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

live8/test86/문제3/황장현.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function solution(files) {
2+
let answerWrap = files.map((file, index) => ({ file, index }));
3+
4+
const compare = (a, b) => {
5+
const reg = /(\D*)([0-9]*)/i;
6+
const A = a.match(reg);
7+
const B = b.match(reg);
8+
9+
const compareHead = A[1].toLowerCase().localeCompare(B[1].toLowerCase());
10+
const compareNumber = (a, b) => {
11+
return parseInt(a) > parseInt(b) ? 1 : parseInt(a) < parseInt(b) ? -1 : 0;
12+
};
13+
return compareHead === 0 ? compareNumber(A[2], B[2]) : compareHead;
14+
};
15+
16+
answerWrap.sort((a, b) => {
17+
const result = compare(a.file, b.file);
18+
return result === 0 ? a.index - b.index : result;
19+
});
20+
21+
return answerWrap.map((answer) => answer.file);
22+
}
23+
24+
console.log(
25+
solution([
26+
'img12.png',
27+
'img10.png',
28+
'img02.png',
29+
'img1.png',
30+
'IMG01.GIF',
31+
'img2.JPG',
32+
])
33+
);

0 commit comments

Comments
 (0)