SOURCE

function compose(funcs) {
  if (!Array.isArray(funcs) || funcs.length == 0) return;
  return (arg) => {
    return funcs.reduce((value, func) => {
    	return func(value);
 		}, arg)
  }
}

const add = (x) => x + 2;
const mul = x => x * x;
const enhance = compose([add, mul]);
console.log(enhance(3));
console 命令行工具 X clear

                    
>
console