Published in: Ruby
URL: http://blog.jayfields.com/2008/03/ruby-inject.html
Expand |
Embed | Plain Text
#Set up the hours array hours = [8, 8, 8, 8] #Run the inject method on the Array total_hours = hours.inject {|result, element| result + element} #Output total hours puts total_hours #=> 32
You need to login to post a comment.
