Created
November 20, 2014 14:02
-
-
Save freesia/c13510002890cdb23160 to your computer and use it in GitHub Desktop.
Unique elements in swift array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func distinct<T: Equatable>( source: [T] ) -> [T] | |
{ | |
var unique = [T]() | |
for item in source | |
{ | |
if !contains( unique, item ) { | |
unique.append( item ) | |
} | |
} | |
return unique | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment