# Problem:
#
# Given a string, write a method `palindrome_substrings` which returns
# all the substrings from a given string which are palindromes. Consider
# palindrome words case sensitive.
#
#
# Algo:
#
# split a string into an array of characters
# use subset of elements in the array using a range with the pair of indexes
# will return a new array
# the new array then has the join method called on it
# assigned to the variable substring
# if the substring is not equal to string and longer than a single character
# substring is pushed to the substrings array
#
# substrings can be accessed using an until loop with an incrementor,
# i and using a while loop with a decrementor, j
# the until's checks to see if i is greater than or equal j
# the 2 indexs of the range essentially meet in the middle

def palindrome_substrings(string)
  array = string.chars
  i = 0
  j = -1
  substrings = []

  until i >= j
    while j > 0
      substring = array[i..j].join
      substrings.push(substring) if substring.length > 1 && substring != string
      j -= 1
    end

    i += 1
    j = string.length - 1
  end

  substrings.select { |elem| elem == elem.reverse }
end

p palindrome_substrings('supercalifragilisticexpialidocious') == ['ili']
p palindrome_substrings('abcddcbA') == %w(bcddcb cddc dd)
p palindrome_substrings('palindrome') == []
p palindrome_substrings('') == []
