File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
array-reduce-transformation Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ Step 2. Add the dependency
49
49
50
50
<summary >展开查看</summary >
51
51
52
+ https://leetcode.cn/problems/array-reduce-transformation/
53
+
54
+ https://leetcode.cn/problems/curry
55
+
52
56
https://leetcode.cn/problems/memoize-ii/
53
57
54
58
https://leetcode.cn/problems/cache-with-time-limit/
Original file line number Diff line number Diff line change
1
+ type Fn = ( accum : number , curr : number ) => number ;
2
+
3
+ function reduce ( nums : number [ ] , fn : Fn , init : number ) : number {
4
+ for ( const v of nums ) {
5
+ init = fn ( init , v ) ;
6
+ }
7
+ return init ;
8
+ }
9
+ export { reduce as default } ;
10
+ export type { Fn } ;
Original file line number Diff line number Diff line change
1
+ // deno-lint-ignore ban-types
2
+ function curry ( fn : Function ) : Function {
3
+ const length = fn . length ;
4
+ return function curried ( ...args : any [ ] ) {
5
+ if ( args . length === length ) return fn ( ...args ) ;
6
+ if ( args . length < length ) {
7
+ return curry ( fn . bind ( null , ...args ) ) ;
8
+ }
9
+ throw new Error ( "arguments length mismatch" ) ;
10
+ } ;
11
+ }
12
+
13
+ /**
14
+ * function sum(a, b) { return a + b; }
15
+ * const csum = curry(sum);
16
+ * csum(1)(2) // 3
17
+ */
18
+
19
+ export default curry ;
You can’t perform that action at this time.
0 commit comments