Cometin'

프로그래머스-수박수박수박 - Javascript

2021-08-27 at Algorithm category

정수 n이 주어졌을 때 "수", "박"을 순서와 n에 맞게 반환하는 문제. repeat을 이용하여 긴 문자열을 만든 후 slice를 이용해 처음부터 n까지 잘라서 반환하여 풀었다.

const solution = (n) => "수박".repeat(n/2+1).slice(0, n);

hyesungoh

Personal blog by hyesungoh.

I like to share my knowledge for those who wandering in issue.