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

TASK: Intersection of Two Arrays

Write a function 'intersection(nums1, nums2)' that returns the common elements of the two given arrays as a unique array. The order of the result does not matter.

STARTER CODE (javascript):
function intersection(nums1, nums2) {
  // Write your code here
}

module.exports = { intersection };


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 intersection(nums1, nums2) {
  const values = new Set(nums1);
  const result = [];

  for (const num of nums2) {
    if (values.delete(num)) {
      result.push(num);
    }
  }

  return result;
}

module.exports = { intersection };
```