I ask a user for input, and store it as hashes inside an array. I need to extract the values that share the same key from those hashes. I want to print the names of students that belong to the same cohort like this:
"May cohort students are: Brian, Penelope"
"June cohort students are: Fred, Pedro"
How could I do this? I need help with this method:
def print(students)
#go through all hashes in 'students' and group them by cohort
#print each cohort separately
end
so that I can do using map
and select
:
def input_students
puts "Please enter the names of the students"
puts "To finish, just hit return twice"
students = []
name = gets.chomp
puts "In which cohort is this student?"
cohort = gets.chomp
while !name.empty? do
students << {cohort.to_sym => name}
name = gets.chomp
cohort = gets.chomp
end
students
end
students = input_students
print(students)
But I get:
"no implicit conversion of Symbol to Integer"