Last active
January 3, 2019 13:06
-
-
Save deHelden/2f9a7ca297d4d3782109963ce49f9ce1 to your computer and use it in GitHub Desktop.
Short script, that transforms 2 arrays into hash and defines relations(bigger&smaller&same) between key and value
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
# 1) В одном массиве записано количество мячей, забитых футбольной командой в каждой из 20 игр, | |
# в другом - количество пропущенных мячей в этой же игре. Для каждой игры определите | |
# словесный результат игры (выигрыш, проигрыш или ничью). (edited) | |
class GameStatisticAttraction | |
def perform | |
goal = Array.new(20){rand(1...10)} | |
miss = Array.new(20){rand(1...10)} | |
game = Hash[goal.zip(miss)] | |
compare(game) | |
end | |
def compare(game) | |
game.each do |goals, misses| | |
compare = "#{goals} : #{misses} it's " | |
if goals > misses | |
puts "#{compare} win" | |
elsif goals < misses | |
puts "#{compare} lose" | |
else | |
puts "#{compare} draw" | |
end | |
end | |
end | |
end | |
# GameStatisticAttraction.new.perform; |
Зачем тут приведение типов?
Hash[goal.zip(miss)]
оно же и так будет работать :)
Привык работать с хэшами, в моей практике с ними проще работать в долгосрочной перспективе. В ревизии можно увидеть, что ранее приведение типа я не сохранял, оба варианта валидны?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Зачем тут приведение типов?
Hash[goal.zip(miss)]
оно же и так будет работать :)