aboutsummaryrefslogblamecommitdiffstats
path: root/2629/main.js
blob: 67e8ff7acfa1fa9aecffbe04c430db121bed76ea (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                     
#!/usr/bin/env node
/**
 * @param {Function[]} functions
 * @return {Function}
 */
var compose = function (functions) {
  return function (x) {
    var result = x;
    for (var i = functions.length - 1; i >= 0; i--) {
      result = functions[i](result);
    }
    return result;
  };
};

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