Skip to content

Commit 746396e

Browse files
yongchansonprove-ability
authored andcommitted
가운데-글자-가져오기 - 솔루션 추가
1 parent 7ce8b59 commit 746396e

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
@@ -6,4 +6,15 @@ function solution(s) {
66
const length = s.length
77
answer = (length % 2) !== 0 ? s[Math.floor(length / 2)] : s.slice((length / 2) - 1, (length / 2) + 1)
88
return answer;
9-
}
9+
}
10+
11+
//정답 2 - yongchanson
12+
function solution(s) {
13+
var answer = "";
14+
let L2 = s.length / 2;
15+
16+
answer =
17+
s.length % 2 == 0 ? s[L2 - 1] + s[L2] : (answer = s[Math.ceil(L2 - 1)]);
18+
19+
return answer;
20+
}

0 commit comments

Comments
 (0)