题目:2629.复合函数

​​题目来源:

        leetcode题目,网址:2629. 复合函数 - 力扣(LeetCode)

解题思路:

        倒序遍历计算。

解题代码:

/**
 * @param {Function[]} functions
 * @return {Function}
 */
var compose = function(functions) {
	return function(x) {
        for(let i=functions.length-1;i>=0;i--){
            x=functions[i](x);
        }
        return x;

    }
};

/**
 * const fn = compose([x => x + 1, x => 2 * x])
 * fn(4) // 9
 */
 
 

总结:

        无官方题解。

        这是函数数组?


扫描二维码关注公众号,回复: 16428864 查看本文章

猜你喜欢

转载自blog.csdn.net/2301_76145947/article/details/132646792