Retired

Remove Duplicates (retired)

1,894 of 6,723richardhsu

Description:

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.

Example

puts unique([1, 5, 2, 0, 2, -3, 1, 10]).inspect
[1, 5, 2, 0, -3, 10]

puts unique([]).inspect
[]

puts unique([5, 2, 1, 3]).inspect
[5, 2, 1, 3]
unique([1, 5, 2, 0, 2, -3, 1, 10])
# -> [1, 5, 2, 0, -3, 10]

unique([])
# -> []

unique([5, 2, 1, 3])
# -> [5, 2, 1, 3]
UniqueArray.unique([1, 5, 2, 0, 2, -3, 1, 10]) 
// -> [1, 5, 2, 0, -3, 10]
unique {1, 5, 2, 0, 2, -3, 1, 10}  --> {1, 5, 2, 0, -3, 10}
λ unique [1,5,2,0,2,-3,1,10]
[1,5,2,0,-3,10]
print unique([1, 5, 2, 0, 2, -3, 1, 10])
[1, 5, 2, 0, -3, 10]

print unique([])
[]

print unique([5, 2, 1, 3])
[5, 2, 1, 3]
Arrays
Fundamentals

More By Author:

Check out these other kata created by richardhsu

Stats:

CreatedAug 7, 2014
Warriors Trained11994
Total Skips1796
Total Code Submissions21186
Total Times Completed6723
Ruby Completions1894
CoffeeScript Completions209
Java Completions2502
Haskell Completions363
Python Completions1936
C# Completions243
Lua Completions9
Total Stars121
% of votes with a positive feedback rating91% of 608
Total "Very Satisfied" Votes511
Total "Somewhat Satisfied" Votes81
Total "Not Satisfied" Votes16
Ad
Contributors
  • richardhsu Avatar
  • jhoffner Avatar
  • OverZealous Avatar
  • Ivan Diachenko Avatar
  • leviathan Avatar
  • user578387 Avatar
  • El Corto Avatar
  • aryan-firouzian Avatar
  • Voile Avatar
  • monadius Avatar
  • fcr-- Avatar
Ad