Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1102c9d

Browse files
chaerin-devprove-ability
authored andcommitted
Add 문자열-내-마음대로-정렬하기.js
1 parent 602fd1f commit 1102c9d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎level-1/문자열-내-마음대로-정렬하기.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ function solution(strings, n) {
1010
return 0
1111
})
1212
return answer;
13-
}
13+
}
14+
15+
//정답 2 - chaerin-dev
16+
function solution(strings, n) {
17+
return strings.sort((a, b) => {
18+
// 인덱스 n번째 글자를 기준으로 오름차순 정렬
19+
if (a[n] > b[n]) return 1;
20+
else if (a[n] < b[n]) return -1;
21+
// 인덱스 n번째 글자가 같으면 사전순 정렬
22+
else return a > b ? 1 : -1;
23+
});
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /