Exercise 10: Find Union of Multiple Arrays
Problem Statement
Function `union(...arrays)` banao jo sabhi arrays ke unique elements return kare.
Example: union([1, 2], [2, 3], [3, 4]) → [1, 2, 3, 4]
Sample Output:
union([1, 2], [2, 3], [3, 4]) => [1, 2, 3, 4] union([1, 1, 2], [2, 3]) => [1, 2, 3]
Solution
const union = (...arrays) => [...new Set(arrays.flat())];Explanation
Overall Goal:
- Multiple arrays ke unique elements combine karna.
Real world:
- Data merging: combine multiple sources.
- Set operations: union operation.