Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Remove Duplicates

Working With Arraysmedium

Course · Section 11: Working With Arrays · Lecture 149: Simple Array Methods

Implement `removeDuplicates(arr)` that returns a new array with duplicate values removed, preserving the original order.

Sample tests

Input: removeDuplicates([1,2,2,3,3,3])
Output: [1,2,3]
Input: removeDuplicates(["a","b","a"])
Output: ["a","b"]

+ 2 hidden tests run on Submit.

Hints

Common pitfalls
  • Objects are compared by reference, so a Set will not dedupe equal-looking objects.

Learning resources

  • MDN: Set
Approach & explanation (try first)

new Set keeps first occurrences in order; spreading returns the deduplicated array.

Loading...
⌘/Ctrl + Enter

Run your code to see results.