Created
January 3, 2019 16:40
-
-
Save deHelden/6c5050da6b68d9d1af2f8eacd4c904b7 to your computer and use it in GitHub Desktop.
[Task 2] Script finds the tallest student in a group
This file contains 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
# 2) В одном массиве записан рост некоторых студентов, а в другом | |
# (с тем же числом элементов) - их фамилии в том же порядке, в котором указан рост. | |
# Известно, что все студенты разного роста. Напечатайте фамилию самого высокого студента. | |
def perform | |
growth = Array.new(6){rand(150..200)} | |
surname = ["Anderson", "Ashwoon", "Aikin", "Bateman", "Bongard", "Bowers"] | |
group = surname.zip(growth) | |
group_h = Hash[group] | |
highest_growth = group_h.values.max | |
highest_student = group_h.select{|key, value| value == highest_growth} | |
highest_student_name = highest_student.keys.first | |
puts "The highest student (#{highest_growth}) is #{highest_student_name}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment