filter through array of arrays ruby

array = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]

result = array.flat_map { |sub_array| sub_array.select(&:even?) }
  1. array is initialized as an array of arrays containing integers.
  2. flat_map iterates through each sub-array.
  3. Within each sub-array, select filters elements based on the condition &:even?, which checks if the element is even.
  4. The selected elements are flattened and stored in the result variable as a single array.