I have a ruby hash containing student name and mark as follows.
student_marks = {
"Alex" => 50,
"Beth" => 54,
"Matt" => 50
}
I am looking for a solution to group students according to their mark.
{
50 => ["Alex", "Matt"],
54 => ["Beth"]
}
I have tried group_by but it didn't give me the desired result. Following is the result of using group_by.
student_marks.group_by {|k,v| v}
{50=>[["Alex", 50], ["Matt", 50]], 54=>[["Beth", 54]]}
Thanks in advance.