aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x2629/main.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/2629/main.js b/2629/main.js
new file mode 100755
index 0000000..67e8ff7
--- /dev/null
+++ b/2629/main.js
@@ -0,0 +1,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