Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/journal-cli/array.rb
Overview
Array helpers
Instance Method Summary collapse
-
#longest ⇒ String
Find the longest element in an array of strings.
-
#shortest ⇒ String
Find the shortest element in an array of strings.
Instance Method Details
#longest ⇒ String
Find the longest element in an array of strings
21 22 23 |
# File 'lib/journal-cli/array.rb', line 21 def longest inject { |memo, word| (memo.length > word.length) ? memo : word } end |
#shortest ⇒ String
Find the shortest element in an array of strings
12 13 14 |
# File 'lib/journal-cli/array.rb', line 12 def shortest inject { |memo, word| (memo.length < word.length) ? memo : word } end |