I have the following hashes:
WorkersPay
:
{"Aaron"=>[300], "Alex"=>[684], ... , "Wendy"=>[792] , "Zach"=>[281]}
and WorkersHrs
:
{"Aaron"=>[36], "Alex"=>[34], ... , "Wendy"=>[39], "Zach"=>[42]}
Where the ellipses (...) indicate a countably infinite number of names between, "Alex," and, "Wendy."
I want to accomplish two things:
- Pseudo code:
puts "#{worker} worked #{hours} and earned $#{dollars}.00"
for every worker in both WorkersPay and WorkersHrs - Sort that puts not alphabetically, but by the number of hours worked
(if the worker worked zero hours, to list them last and just pseudo
code:
puts "#{worker} worked #{hours} this week"
)
I have searched through SO for days and this is my best code so far:
WorkerHrs.each do |key, array|
WorkerHrs.sort_by { |a, b| a[0] <=> b[0] }
WorkerPay.each do |key2, array2|
if key == key2
if array.inject{|a,i| a*10 + i} == 0
puts "#{key} worked #{array.inject{|a,i| a*10 + i}} hours this week"
else
puts "#{key} worked #{array.inject{|a,i| a*10 + i}} hours and earned $#{array2.inject{|a,i| a*10 + i}}.00"
end
end
end
end
Hoping to achieve this:
John worked 80 hours and earned $36.00
.
.
.
Sam worked 0 hours this week
Where the vertical ellipses indicate the exact same thing as the regular ellipses.
I have never worked with hashes that contain key, array pairs before and would appreciate any and all help getting my horrendous code to work!