Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/journal-cli/array.rb

Overview

Array helpers

Instance Method Summary collapse

Instance Method Details

#longestString

Find the longest element in an array of strings

Returns:

  • (String)

    longest element



21
22
23
# File 'lib/journal-cli/array.rb', line 21

def longest
  inject { |memo, word| (memo.length > word.length) ? memo : word }
end

#shortestString

Find the shortest element in an array of strings

Returns:

  • (String)

    shortest element



12
13
14
# File 'lib/journal-cli/array.rb', line 12

def shortest
  inject { |memo, word| (memo.length < word.length) ? memo : word }
end