Sum of word lengths : inject « Array « Ruby






Sum of word lengths


%w[pea queue are].inject(0) {|total, word| total + word.length }  # => 11

 

Related examples in the same category

1.Sum an array with inject
2.Building Up a Hash Using Injection