2629.复合函数
链接:2629.复合函数
难度:Easy
标签:
简介:请你编写一个函数,它接收一个函数数组 [f1, f2, f3,…], fn] ,并返回一个新的函数 fn ,它是函数数组的 复合函数 。
题解 1 - typescript
- 编辑时间:2023-04-23
- 执行用时:72ms
- 内存消耗:45MB
- 编程语言:typescript
- 解法介绍:遍历。
type F = (x: number) => number;
function compose(functions: F[]): F {
functions = functions.reverse()
return function (x) {
for (const f of functions) x = f(x);
return x;
}
};