CS/SICP in JS

연습문제 1.30

띵킹 2023. 2. 18. 14:04
function next(n) {
    return n+1;
}

function sum(term, a, next, b) {
    function iter(a, result) {
        return a > b 
              ? result
              : iter(next(a), result + term(a));
    }
    return iter(a, 0);
}

Javascirpt의 내장 함수 reduce가 생각나서 금방 해결했다

728x90

'CS > SICP in JS' 카테고리의 다른 글

연습문제 1.32, 1.33  (0) 2023.02.19
연습문제 1.31  (0) 2023.02.18
연습문제 1.17  (0) 2023.02.11
연습문제 1.16  (0) 2023.02.11
연습문제 1.12  (0) 2023.02.10