Created
July 12, 2011 22:20
-
-
Save kineticac/1079126 to your computer and use it in GitHub Desktop.
custom unique method for coach arrays
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
def self.unique(coaches) | |
return coaches if coaches.empty? | |
raise ArgumentError, "requires array of coaches as an argument" if(coaches.class != Array || coaches.first.class != Coach) | |
coach_ids = [] | |
unique_coaches = [] | |
coaches.each do |coach| | |
unless coach_ids.include?(coach.id) | |
coach_ids << coach.id | |
unique_coaches << coach | |
end | |
end | |
return unique_coaches | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment