Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Merge Unique with Spread

Data Structures, Operators & Stringsmedium

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `mergeUnique(a, b)` returning the unique values from both arrays, using spread and a Set.

Sample tests

Input: mergeUnique([1,2], [2,3])
Output: [1,2,3]
Input: mergeUnique([], [1])
Output: [1]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Concatenating without deduping leaves repeats.

Learning resources

  • MDN: Destructuring assignment
Visualize this concept: Maps and Sets →
Approach & explanation (try first)

Spreading both arrays and passing through a Set merges them while removing duplicates.

Loading...
⌘/Ctrl + Enter

Run your code to see results.