In this post, we will solve Ruby Control Structures – Each HackerRank Solution. This problem (Ruby Control Structures – Each Solution) is a part of HackerRank Ruby series.
Ruby offers control structures that let you iterate through its collections. One such control structure is
As you already know, HackerRank conducts many contests, and for every user who participates in a contest we update their score once the contest ends. You will be given a method called
scoring with an array passed as an argument. Elements of the array are of the class
User class has a method
Your task is to iterate through each of the elements in the array using
each and call the method
update_score on every element.
array.each do |user| # call update_score on `user` here end
Solution – Ruby Control Structures – Each
def scoring(array) # iterate through each of the element in array using *each* and call update_score on it array.each do |u| u.update_score end end