Today's JS challenge is about Memoization. They ask you to write a function that accepts another function, and it caches the result of the function calls. If the result has already been computed, we return the cached value without having to run the function again. If no value is stored, we compute the value, store it, and return it. I accomplished this by declaring an object in my outer function to serve as a the cache. We then return a function that accepts an arbitrary number of arguments. I chose to use the JSON.stringify() method to turn the arguments into a usable object key. We check if the key is in our cache, and if so, return its value. Otherwise we compute its value based on the function and arguments, add it to our cache, and return.
Sunday, May 14, 2023
Subscribe to:
Post Comments (Atom)
190: Sablier
The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...
-
The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...
-
The ZKasino project recently exit scammed over 33 million dollars worth of Ethereum. he recent debacle surrounding ZKasino offers valuable...
-
In addition to its native SDK, Hedera also supports smart contracts in a platform compatible with the Ethereum Virtual Machine. This allows ...
No comments:
Post a Comment