Implement a Memoization Utility That Caches Function Results by Arguments

Write a memoize(fn) higher-order function that caches the return value of fn based on its input arguments. On subsequent calls with the same arguments, return the cached result immediately without re-executing fn. Handle multi-argument functions by serializing the args as a cache key (using JSON.stringify or a Map with structured keys). Discuss cache size limits, LRU eviction, and WeakMap-based caching for object arguments.

Examples
Input: []
Output:
Hints

Implement a Memoization Utility That Caches Function Results by Arguments

Write a memoize(fn) higher-order function that caches the return value of fn based on its input arguments. On subsequent calls with the same arguments, return the cached result immediately without re-executing fn. Handle multi-argument functions by serializing the args as a cache key (using JSON.stringify or a Map with structured keys). Discuss cache size limits, LRU eviction, and WeakMap-based caching for object arguments.