Skip to content

Commit a8c0db9

Browse files
day 08 task complete
1 parent 8829321 commit a8c0db9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

day08/leetcode2629.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// 2629. Function Composition
2+
// URL -> https://leetcode.com/problems/function-composition
3+
4+
/**
5+
* @param {Function[]} functions
6+
* @return {Function}
7+
*/
8+
var compose = function (functions) {
9+
10+
return function (x) {
11+
for (let i = functions.length - 1; i >= 0; i--) {
12+
x = functions[i](x);
13+
}
14+
return x;
15+
}
16+
};
17+
18+
/**
19+
* const fn = compose([x => x + 1, x => 2 * x])
20+
* fn(4) // 9
21+
*/

0 commit comments

Comments
 (0)