File tree Expand file tree Collapse file tree 1 file changed +5
-14
lines changed
src/main/kotlin/g2601_2700/s2630_memoize_ii Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -13,31 +13,22 @@ function memoize(fn: Fn): Fn {
13
13
currentCache = new Map ( )
14
14
cache . set ( args . length , currentCache )
15
15
}
16
-
17
16
for ( let i = 0 , len = args . length ; i <= len ; i ++ ) {
18
17
const arg = args [ i ]
19
18
const isEnd = i >= len - 1
20
-
21
19
if ( currentCache . has ( arg ) ) {
22
20
if ( isEnd ) {
23
21
return currentCache . get ( arg )
24
22
} else {
25
23
currentCache = currentCache . get ( arg )
26
24
}
27
- } else {
28
- if ( isEnd ) {
29
- break
30
- } else {
31
- const newSubCache = new Map ( )
32
-
33
- currentCache . set ( arg , newSubCache )
34
- currentCache = newSubCache
35
- }
25
+ } else if ( ! isEnd ) {
26
+ const newSubCache = new Map ( )
27
+ currentCache . set ( arg , newSubCache )
28
+ currentCache = newSubCache
36
29
}
37
30
}
38
-
39
- let value = fn . apply ( null , args )
40
-
31
+ let value = fn . apply ( ...args )
41
32
currentCache . set ( args [ args . length - 1 ] , value )
42
33
return value
43
34
}
You can’t perform that action at this time.
0 commit comments