[JS] 프로그래머스 Lv.1: 정답률 82%

ahyes·2022년 12월 18일
0
post-thumbnail

안녕하세요.
이어서 정답률 82% 문제를 풀어보겠습니다.

  1. 없는 숫자 더하기
function solution(numbers) {
    return 45-numbers.reduce((a,b)=>a+b,0);
}
  1. 가운데 글자 가져오기
function solution(s) {
    return s.length%2?s[Math.floor(s.length/2)]:s[Math.floor(s.length/2-1)]+s[Math.floor(s.length/2)];
}
  1. 수박수박수박수박수박수?
function solution(n) {
    var answer = '';
    let i = 0;
    while(i<n){
        i%2?answer+="박":answer+="수";
        i++;
    }
    return answer;
}
profile
티스토리로 이사갑니다. https://useyhnha.tistory.com/

0개의 댓글