Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/array.rb

Overview

Array helpers

Instance Method Summary collapse

Instance Method Details

#longest_elementString

This method takes an array and returns the longest element of that array.

Returns:

  • (String)

    Longest string in array



9
10
11
# File 'lib/searchlink/array.rb', line 9

def longest_element
  longest_elements[0]
end

#longest_elementsArray

Finds the longest elements and returns an Array

Returns:

  • (Array)

    array of longest elements



16
17
18
# File 'lib/searchlink/array.rb', line 16

def longest_elements
  group_by(&:size).max.last
end

#shortest_elementString

Finds the shortest element in an array of strings

Returns:

  • (String)

    first element among shortest elements



23
24
25
# File 'lib/searchlink/array.rb', line 23

def shortest_element
  shortest_elements[0]
end

#shortest_elementsArray

Finds the shortest elements in an array of strings

Returns:

  • (Array)

    array of shortest elements



30
31
32
# File 'lib/searchlink/array.rb', line 30

def shortest_elements
  group_by(&:size).min.last
end