프로그래머스 Lv2 [3차] 파일명 정렬

taeng·2022년 2월 25일
0

알고리즘

목록 보기
4/12

function solution(files) {
var z= files.sort((a,b)=>{
var [ahead,anumber,atail] =a.toUpperCase().split(/([0-9]{1,})/);
var [bhead,bnumber,btail] =b.toUpperCase().split(/([0-9]{1,})/);
if(ahead!=bhead){
return ahead.localeCompare(bhead);
}else{
if(anumber!=bnumber){
return anumber-bnumber
}

 }
})
 return z

}

profile
주니어 백엔드 개발자 공부 정리

0개의 댓글