본문 바로가기

프로그래머스(코딩 테스트)/Lv.0

짝수의 합

// javascript
const solution = (n) => {
    return Array.from({ length: Math.floor(n / 2) }, (_, index) => (index + 1) * 2)
                .reduce((sum, num) => sum + num, 0);
};

 

// typescript
const solution = (n:number):number => {
    return Array.from({ length: Math.floor(n / 2) }, (_, index) => (index + 1) * 2)
                .reduce((sum, num) => sum + num, 0);
};

 

'프로그래머스(코딩 테스트) > Lv.0' 카테고리의 다른 글

짝수는 싫어요  (0) 2024.10.15
편지  (0) 2024.10.15
중복된 문자 제거  (0) 2024.10.15
아이스 아메리카노  (0) 2024.10.15
숫자 비교하기  (0) 2024.10.15