Skip to learning content
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 focused browser IDE · Review questions you keep missing

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 or indents; Shift plus Tab outdents. Press Escape, then Tab, to leave the editor. Press Command or Control plus Enter to check; add Shift to run examples.
⌘/Ctrl + Enter checks · ⇧ + ⌘/Ctrl + Enter runs examples · ⌘/Ctrl + S saves · Escape then Tab exits
View example solution

Compare the approach with your draft. Opening this reference does not replace your code or update progress.

Read-only code example. Use the arrow keys to navigate the code. Press Escape, then Tab, to leave the code example.
Resultsnew

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