===== ISTEM =====
Solve the following programming task.

TASK: Memoize Function Results

Write a pure 'memoize(fn)' wrapper that returns the cached result for the same arguments instead of recomputing it.

STARTER CODE (javascript):
function memoize(fn) {
  // Write your code here
}

module.exports = { memoize };


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```javascript
function memoize(fn) {
  const cache = new Map();
  const RESULT = Symbol("result");

  return function (...args) {
    let node = cache;

    for (const arg of args) {
      if (!node.has(arg)) {
        node.set(arg, new Map());
      }
      node = node.get(arg);
    }

    if (node.has(RESULT)) {
      return node.get(RESULT);
    }

    const result = fn.apply(this, args);
    node.set(RESULT, result);
    return result;
  };
}

module.exports = { memoize };
```