Method practice · runs on this device

Read it. Write it. Check it.

Work through 6 original coding questions in 2 groups. Your drafts and solved status stay in this browser.

Try “Keep unique values” in the extension-backed IDE

Loading practice progress.

0 of 6 solvedLoading device progress
easynew

Keep unique values

Return the values that appear in the input, keeping only their first appearance. Preserve the original order.

Examples

keeps the first copy of repeated values
Input
[[4,2,4,1,2]]
Expected
[4,2,1]
leaves an already unique list alone
Input
[[3,1,8]]
Expected
[3,1,8]

Constraints

  • The input contains at most 10,000 finite numbers.
  • Do not sort the input.
  • Return a new array.
unique-values.tsSolution.uniqueValues() · browser sandbox
Saved
Code editor. Tab accepts an open suggestion; otherwise it indents. Press Escape, then Tab, to leave the editor. Press Command or Control plus Enter to check your solution.
⌘/Ctrl + Enter checks · ⌘/Ctrl + S saves · Escape then Tab leaves the editor
Resultsnew

Run the examples for a quick pass, or check the full solution to record progress.