Ad
  • Custom User Avatar

    The memoization in javascript is strange because of a few things; which are implemented in this kata:
    Objects in and out of scope of the inner and outer function call when this tests assertions are run are necessary. You want to store records of the innjer function results outside of the it to avoid its execution when it already can have data stored containing its signature, and result.

    The test assertions in this are kind of unclear, you need to store the result of the function in (usually) four concurrent calls:

    1. initial execution, have the return of the inner function, cascade to the wrapper, and store/cache it.
    2. the inner function is validated to have been executed
    3. the data should be propertly retrieved by the cache, the second execution, but from a scope outside of the inner function
    4. the inner function should have not been called again

    Logic map cache(innerfunction) -> check if data is stored -> if it is not store it and run function, otherwise pull from cache without running.

    If you are having trouble understanding, dumping the inner function being passed as a test case, to a string, will likely give you a better understanding.