[Solved] Filter an array of hashes Ruby [closed]


Let’s try this, you have this array

array = [
   {
    "10:45" => 40,
    "11:00" => 40,
    "11:15" => 40,
    "11:30" => 40,
    "13:30" = >35,
    "14:00" => 40,
    "15:00" => 40
   },
   {
    "12:00" => 38,
    "12:45" => 39,
    "13:00" => 39,
    "13:15" => 39,
    "13:30" => 39
   }
]

Let’s remove the duplicate values

def get_results(array)
  final_array = []

  array.each do |hash|
    final_hash = {}

    hash.each do |key, value|
      final_hash[key] = value unless final_hash.values.last == value
    end
    final_array << final_hash
  end
  final_array
end

Hope this helps!

2

solved Filter an array of hashes Ruby [closed]