Over a million developers have joined DZone.

Finding The Length Of The Longest Word

·
Source: Module: Enumerable [ruby-doc.org]



longest = %w{ cat sheep bear }.inject(0) do |memo,word|
  memo >= word.length ? memo : word.length
end
longest                                         #=> 5

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}