def rps_tournament_winner(tournament)
for i in 0..1 do
if tournament[i][1].is_a? Array then
rps_tournament_winner(tournament[i])
else
tournament=rps_game_winner(tournament)
return
end
end
return tournament
end
This is a part of rock-papers-scissors implementation in Ruby
rps_game_winner
takes an array of two arrays in format of
[ ["Allen", "S"], ["Omer", "P"] ]
where first element is player's name, second element is their decision and returns the winner.
rps_tournament_winner
takes an input of nested arrays with arbitrary depth like
[
[
[ ["Armando", "P"], ["Dave", "S"] ],
[ ["Richard", "R"], ["Michael", "S"] ],
],
[
[ ["Allen", "S"], ["Omer", "P"] ],
[ ["David E.", "R"], ["Richard X.", "P"] ]
]
]
What I am trying to do is modifying the original input as the function makes progress but the input comes out as it came in. Incorporating global variables are a solution but this is a work to be graded with an auto grader and I suspect it is just going to push some input directly to the function and compare the output so its not an option.
;). (I assume you mean classes, I'm just being pedantic.)