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 {
1313 currentCache = new Map ( )
1414 cache . set ( args . length , currentCache )
1515 }
16-
1716 for ( let i = 0 , len = args . length ; i <= len ; i ++ ) {
1817 const arg = args [ i ]
1918 const isEnd = i >= len - 1
20-
2119 if ( currentCache . has ( arg ) ) {
2220 if ( isEnd ) {
2321 return currentCache . get ( arg )
2422 } else {
2523 currentCache = currentCache . get ( arg )
2624 }
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
3629 }
3730 }
38-
39- let value = fn . apply ( null , args )
40-
31+ let value = fn . apply ( ...args )
4132 currentCache . set ( args [ args . length - 1 ] , value )
4233 return value
4334 }
You can’t perform that action at this time.
0 commit comments