Remove Duplicates
You are to write a function called unique that takes an array of integers and returns the array with duplicates removed. It must return the values in the same order as first seen in the given array. Thus no sorting should be done, if 52 appears before 10 in the given array then it should also be that 52 appears before 10 in the returned array.
Assumptions
All values given are integers (they can be positive or negative).
You are given an array but it may be empty.
They array may have duplicates or it may not.
You cannot use the uniq method on Arrays (don't even try it), or the nub function from Data.List.
Example
UniqueArray.unique([1, 5, 2, 0, 2, -3, 1, 10])
// -> [1, 5, 2, 0, -3, 10]
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #88 Which are in? (6kyu) (0) | 2018.07.30 |
---|---|
codewars #87 Extract the IDs from the data set (6kyu) (0) | 2018.07.27 |
codewars #85 Circularly Sorted Array (6kyu) (0) | 2018.07.25 |
codewars #84Can you get the loop ? (5kyu) (0) | 2018.07.24 |
codewars #83 Stop gninnipS My sdroW! (6kyu) (0) | 2018.07.23 |