Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Unique Values with a Set

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 122: Sets

Implement `uniqueValues(arr)` returning the distinct values in order, using a Set.

Sample tests

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

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Objects in a Set are compared by reference, not value.
Visualize this concept: Maps and Sets →
Approach & explanation (try first)

A Set drops duplicates while preserving first-seen order.

Loading...
⌘/Ctrl + Enter

Run your code to see results.