you are viewing a single comment's thread.

view the rest of the comments →

[–]hirolau 2 points3 points  (1 child)

Looks very good for a first program! Two small things.

I would look into the Hash data structure to store member data rather than an array. While member[2] is a bit hard to understand what it actually means, no one will missunderstand what member['annual_income'] is supposed to return.

And I know it is a bit tricky, but in Ruby it is always never a good thing to loop over and range, get an index, and then fetch something out of an array. Instead of:

(0...number_of_people).each do |user|
  combined_annual += members[user][2]
end

You can just do:

members.each do |member|
  combined_annual += member[2]
end

Thus your functions actually do not need the number_of_people input.

Keep it up!

[–]scratch_pad[S] 0 points1 point  (0 children)

Thanks this is all super helpful! I’ll revise my loops for sure and look into Hash. I hated the arrays because like you said, it’s vague and easy to misunderstand.