Created
December 11, 2013 14:51
-
-
Save kyledecot/7911708 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Given a CSV of people, display them grouped together by their favorite colors | |
require 'csv' | |
# Gather the data... | |
results = Array.new.tap do |a| | |
CSV.foreach File.expand_path('../people.csv', __FILE__), headers: true do |row| | |
a << row.to_hash | |
end | |
end.reject do |person| | |
person['Favorite Color'].nil? | |
end.group_by do |person| | |
person['Favorite Color'] | |
end | |
# Display it in some kind of useful way... | |
results.each do |color, people| | |
puts color | |
puts "===============" | |
people.each do |person| | |
puts "#{person['First Name']} #{person['Last Name']}" | |
end | |
puts "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment