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

TASK: Deep Clone an Object

Write a function 'deepClone(obj)' that deeply copies a given JavaScript object or array (including nested objects, arrays and primitives) without sharing references. It must also clone Date and RegExp objects.

STARTER CODE (javascript):
function deepClone(obj) {
  // Write your code here
}

module.exports = { deepClone };


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 deepClone(obj, map = new WeakMap()) {
  // Handle primitives and functions
  if (obj === null || typeof obj !== 'object') return obj;

  // Handle circular references
  if (map.has(obj)) return map.get(obj);

  // Handle Date
  if (obj instanceof Date) {
    const copy = new Date(obj.getTime());
    map.set(obj, copy);
    return copy;
  }

  // Handle RegExp
  if (obj instanceof RegExp) {
    const copy = new RegExp(obj.source, obj.flags);
    map.set(obj, copy);
    return copy;
  }

  // Handle Array
  if (Array.isArray(obj)) {
    const copy = [];
    map.set(obj, copy);
    obj.forEach((item, index) => {
      copy[index] = deepClone(item, map);
    });
    return copy;
  }

  // Handle plain objects (and other objects)
  const copy = Object.create(Object.getPrototypeOf(obj));
  map.set(obj, copy);
  Reflect.ownKeys(obj).forEach(key => {
    const desc = Object.getOwnPropertyDescriptor(obj, key);
    if (desc.hasOwnProperty('value')) {
      desc.value = deepClone(desc.value, map);
    }
    Object.defineProperty(copy, key, desc);
  });
  return copy;
}

module.exports = { deepClone };
```
