Ad
  • Custom User Avatar

    should evict the least recently used item when maxSize is exceeded, it seems that something is not working and Idk why, the maxSize is 3 here but it was supposed to be 2.

    options { maxSize: 3 }
    [1]
    [2]
    [3]
    [1]
    [4]
    delete [1]
    [2]
    

    It fails in this test specifically

        it("should evict the least recently used item when maxSize is exceeded", () => {
            let callCount = 0;
            const fn = (x: number) => {
                callCount++;
                return x * 2;
            };
            const memoizedFn = memoize(fn, { maxSize: 2 });
    
            memoizedFn(1);
            memoizedFn(2);
            memoizedFn(3); // This should evict the result for 1
    
            assert.equal(callCount, 3);
            assert.equal(memoizedFn(1), 2); // This should call the function again
            assert.equal(callCount, 4);
        });
    

    Any help is appreciate thanks!

  • Custom User Avatar

    I will be waiting for your feedback after my update

  • Custom User Avatar

    I ran your code through my tests and saw a shortcoming on my end with the tests. I will fix it.
    Thx for issue!

  • Custom User Avatar

    Your function starts caching only after the 25th call. In our task, caching should start from the first call.

    Your function does not consider the maximum cache size. The task requires automatic removal of the least recently used entries when the cache size exceeds the specified limit

    Your function does not manage the time-to-live (TTL) for cached entries. The task requires that entries expire and are removed from the cache after the specified TTL.


    Perhaps I misunderstood your expectations and you were looking for a different response from me. How else can I assist you?

  • Custom User Avatar

    Thanks for the feedback.

    I'll update the advice to mention that JSON.stringify can be used (i agree it's not the optimal solution), and I'll clarify that there are no tests with null, undefined, or <empty item>.

    Is there anything else you'd like to add?

  • Custom User Avatar
    JSON.stringify([undefined]) -> "[null]"
    JSON.stringify([,]) -> "[null]"
    

    Apparently, values passed to the memoised function do not need to be distinguished between null, undefined and <empty item>. This needs to be specified.

    I don't know that I agree with calling JSON.stringify "optimal". At best it's a highly unqualified statement.

  • Custom User Avatar
  • Custom User Avatar

    Okay, I can rework the task.

  • Custom User Avatar

    Johan is absolutely right. There are, in fact, several other kata that handle this specific task.
    You're better off adding a translation to one of them.
    https://www.codewars.com/kata/653c14997bcc1b23f6fbaf75
    https://www.codewars.com/kata/54330fec913a650b640004b1
    https://www.codewars.com/kata/59ffef8246d8434b0700001d

  • Custom User Avatar

    I have described the advantages of the method and where it can be used.

  • Custom User Avatar

    It's difficult to deny that our tasks are similar as they both utilize the memoization mechanism. However, my task is focused on universality, making the memoization function applicable to any function with any number of arguments. Your task, on the other hand, is focused on optimizing performance specifically for recursive functions.

  • Custom User Avatar

    You see more difference than there is. "Duplicate" does not mean an exact copy, it means there is too much similarity. There is too much similarity.

  • Custom User Avatar

    Note that you will never be able to resolve the "Duplicate" issue, so will never be able to republish the kata. Investing time in it is a nice exercise in kata creation, but this kata is doomed to remain in Draft.

  • Custom User Avatar

    Although both tasks involve memoization, the focus and intent behind each task are different:

    1. Your task is specifically designed to test memoization in the context of recursive functions, with an emphasis on currying to handle multiple arguments.
    2. My task, however, is designed to create a generic memoization function that can handle any function, regardless of whether it's recursive or not, and can work seamlessly with any number of arguments. This broadens the applicability and reusability of the memoization technique.
  • Custom User Avatar

    Description extols the virtues of memoisation as if it has no downsides and isn't a balancing act between several resources, all of which are limited.

  • Loading more items...