[LeetCode] 2629. Function Composition

Chobby·2024년 6월 26일
1

LeetCode

목록 보기
5/249

😎나의풀이

함수 배열을 역방향으로 누적하며 더하는 연산이기에 reduce 메서드를 활용하였음

type F = (x: number) => number;

function compose(functions: F[]): F {
    return function(x) {
        return functions.reverse().reduce((acc, cur) => cur(acc), x)
    }
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN