Skip to content

Commit 449ca87

Browse files
committed
https://leetcode.cn/problems/function-composition
1 parent 1a665c5 commit 449ca87

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode.cn/problems/function-composition
53+
5254
https://leetcode.cn/problems/array-reduce-transformation/
5355

5456
https://leetcode.cn/problems/curry

function-composition/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type F = (x: number) => number;
2+
3+
function compose(functions: F[]): F {
4+
return function (x) {
5+
return functions.reduceRight((p, c) => c(p), x);
6+
};
7+
}
8+
9+
export default compose;
10+
11+
export type { F };

0 commit comments

Comments
 (0)