TIL_230601 - 프로그래머스 - Lv1. 없는 숫자 더하기

정윤숙·2023년 6월 1일
0

TIL

목록 보기
161/192
post-thumbnail

📒 오늘의 공부

1. 프로그래머스

Lv1. 없는 숫자 더하기

나의 풀이

const solution = (numbers) =>{
    let answer = 0;
    for(let i=0; i<=9; i++){
        if(!numbers.includes(i)){
           answer+=i
        }

    }
    return answer

}

다른 풀이

function solution(numbers) {
    return 45 - numbers.reduce((cur, acc) => cur + acc, 0);
}
  • 주어진 전체 숫자 활용하기
profile
프론트엔드 개발자

0개의 댓글