Unique and sorted
Read a line of whole numbers separated by spaces. Print the distinct numbers in ascending order, separated by spaces.
Careful: JavaScript's sort() sorts as text by default, so 10 comes before 9 unless you give it a compare function.
Input
3 1 3 2 1
Expected output
1 2 3
Input
10 9 100 9
Expected output
9 10 100
Show a hint
A Set keeps one of each value. sort((a, b) => a - b) sorts numbers properly.
Show a solution
Loading the editor…
Run the tests to check your solution.