diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-01-05 20:55:17 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-01-05 20:55:17 +0000 |
commit | dca8f216affae6b235535e154d53bdc25e6748c8 (patch) | |
tree | c78f46bb397ba7c2840782edbaab566a381cbd72 | |
parent | 2626 (diff) | |
download | leetcode-dca8f216affae6b235535e154d53bdc25e6748c8.tar.gz leetcode-dca8f216affae6b235535e154d53bdc25e6748c8.zip |
2629
-rwxr-xr-x | 2629/main.js | 17 |
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 |