Skip to content

Commit 63a25ea

Browse files
committed
Add 220502 가운데 글자 가져오기.js
1 parent 127533a commit 63a25ea

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

level-1/가운데-글자-가져오기.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ function solution(s) {
3737
: s[s.length / 2 - 1] + s[s.length / 2];
3838
}
3939

40-
40+
// 정답 5 - jaewon1676
41+
function solution(s) {
42+
var answer = '';
43+
44+
if (s.length % 2 == 0 ) { // 짝수일 경우,
45+
answer = s[s.length / 2 - 1] + s[s.length / 2];
46+
} else {
47+
answer = s[parseInt(s.length / 2)]; // 홀수일 경우
48+
}
49+
return answer;
50+
}

0 commit comments

Comments
 (0)