# RELEASE 2: NESTED STRUCTURE GOLF
# Hole 1
# Target element: "FORE"

array = [[1,2], ["inner", ["eagle", "par", ["FORE", "hook"]]]]

# attempts:
# ============================================================
p array[1][1][2][0]

# ============================================================
# Hole 2
# Target element: "congrats!"

hash = {outer: {inner: {"almost" => {3 => "congrats!"}}}}

# attempts:
# ============================================================
p hash[:outer][:inner]["almost"][3]

# ============================================================
# Hole 3
# Target element: "finished"

nested_data = {array: ["array", {hash: "finished"}]}

# attempts:
# ============================================================
p nested_data[:array][1][:hash]

# ============================================================
# RELEASE 3: ITERATE OVER NESTED STRUCTURES

number_array = [5, [10, 15], [20,25,30], 35]

# INITIAL ATTEMPT
# number_array.each do |element1|
#   if element1.kind_of?(Array)
#     element1.each do |element2|
#       p (element2 + 5)
#     end
#   elsif element1.kind_of?(Integer)
#     p (element1 + 5)
#   end
# end

# REFACTORED
number_array = [5, [10, 15], [20,25,30], 35]

number_array.map! do |element_one|
  if element_one.kind_of?(Integer)
    element_one + 5
  elsif element_one.kind_of?(Array)
    element_one.map! do |element_two|
       element_two + 5
    end
  end
end

p number_array

# If you don't care about maintaining the nested structure:
# number_array.flatten!.map! { |element| element + 5 }
# p number_array

# ============================================================
# Bonus:

startup_names = ["bit", ["find", "fast", ["optimize", "scope"]]]

startup_names.flatten!.map! do |item|
  item += "ly"
end

p startup_names

=begin

What are some general rules you can apply to nested arrays?
  You can think of nested array as just multiple single arrays. All the same methods
  and iterators can be applied.
What are some ways you can iterate over nested arrays?
  You can iterate over nested arrays in the same ways that you can iterate over single
  arrays. You can loop through them using each or by using Enumerables. It can get
  complicated though because you may need to use a number of nested iterators.

Did you find any good new methods to implement or did you re-use one you were already
familiar with? What was it and why did you decide that was a good option?
  I've used map! before, but we found it useful again today when when we wanted to add 5
  to the elements in the nested array while maintaining the nested structure. I had also
  heard of flatten before, but had not used it until today. We used it to convert a nested
  array to single array for the bonus challenge. In this case, it made sense because we
  wanted to alter all the items in a nested array and we weren't concerned with maintaining
  the multidimensional structure.

=end