Created
November 7, 2024 06:45
-
-
Save GabrielModog/7e35771da215fe72996fdaeb858cd7b2 to your computer and use it in GitHub Desktop.
weirdRecusriveSumweirdRecusriveSumweirdRecusriveSumweirdRecusriveSum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function weirdRecusriveSum(nums, length, result = 0, index = 0, memo = {}){ | |
| if(length === 0) return result | |
| if(result in memo) return memo[result] | |
| result += nums[index] | |
| length-- | |
| index++ | |
| memo[result] = weirdRecusriveSum(nums, length, result, index, memo) | |
| return memo[result] | |
| } | |
| const sum = new Array(4500).fill(1).map((t,i)=> t+i) | |
| console.log(weirdRecusriveSum(sum, sum.length)) | |
| // console.log("called: " + track + " times") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment