Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hebertialmeida/6ba1331e3bc9ecb0cb89 to your computer and use it in GitHub Desktop.
Save hebertialmeida/6ba1331e3bc9ecb0cb89 to your computer and use it in GitHub Desktop.
Remove repeated values from a INT array, returning the resultant array in the same order as original. Swift implementation.
import UIKit
var numbers = [7, 7, 7, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8]
var filter = [Int]()
for number in numbers {
if !contains(filter, number) {
filter.append(number)
}
}
print(filter)
// Returns [7, 1, 2, 3, 4, 5, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment