Skip to content

Instantly share code, notes, and snippets.

@daiando
Last active December 10, 2015 08:58
Show Gist options
  • Save daiando/0e4bf70137c558866667 to your computer and use it in GitHub Desktop.
Save daiando/0e4bf70137c558866667 to your computer and use it in GitHub Desktop.
def evaluate_num(val)
return "RED" if val <= 2
return "BLUE" if val > 3
end
(1..5).group_by {|x|
evaluate_num(x)
}
#=> {"RED"=>[1, 2], "BLUE"=>[3, 4, 5]}
#marks = {"Ramesh":23, "Vivek":40, "Harsh":88, "Mohammad":60}
def group_by_marks(marks, n)
def evaluate(age, standard)
return "Failed" if age < standard
return "Passed" if age >= standard
end
marks.group_by{|k, v|
evaluate(v, n)
}
end
##=> {"Failed"=>[["Ramesh", 23]], "Passed"=>[["Vivek", 40], ["Harsh", 88], ["Mohammad", 60]]}
def evaluate_num(val)
return "RED" if val <= 2
return "BLUE" if val > 2
end
(1..5).group_by {|x|
evaluate_num(x)
}
=> {"RED"=>[1,2], "BLUE"=>[3, 4, 5]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment