From dca8f216affae6b235535e154d53bdc25e6748c8 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 5 Jan 2024 15:55:17 -0500 Subject: 2629 --- 2629/main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 2629/main.js (limited to '2629') 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 -- cgit v1.2.3