aboutsummaryrefslogtreecommitdiffstats
path: root/2629/main.js
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-05 20:55:17 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-05 20:55:17 +0000
commitdca8f216affae6b235535e154d53bdc25e6748c8 (patch)
treec78f46bb397ba7c2840782edbaab566a381cbd72 /2629/main.js
parent2626 (diff)
downloadleetcode-dca8f216affae6b235535e154d53bdc25e6748c8.tar.gz
leetcode-dca8f216affae6b235535e154d53bdc25e6748c8.zip
2629
Diffstat (limited to '2629/main.js')
-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