In this case students is an array of hashes showing student names and the cohort they are enrolled in
The output summarises by cohort and lists the relevant enrolled student names
def print_by_category(students)
# print the students grouped by cohort
cohort_array = []
students.each do |hash|
cohort_array.push(hash[:cohort]).uniq!
end
cohort_array.each do |cohort|
puts cohort
students.each_with_index do |student, index|
if student[:cohort] == cohort
puts "#{index + 1}. #{student[:name]} (#{student[:cohort]} cohort)".center(50)
end
end
end
end