i have array of hashes:
[ [0] { "10:45" => 40, "11:00" => 40, "11:15" => 40, "11:30" => 40 "13:30" = >35, "14:00" => 40, "15:00" => 40 }, [1] { "12:00" => 38, "12:45" => 39, "13:00" => 39, "13:15" => 39, "13:30" => 39 } ] i need new filtered array:
[ [0] { "10:45" => 40, "13:30" = >35, "14:00" => 40 }, [1] { "12:00" => 38, "12:45" => 39 } ] in other words "delete key/value if value equals right before value".
let's try this, have 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 duplicate values
def get_results(array) final_array = [] array.each |hash| final_hash = {} hash.each |key, value| final_hash[key] = value unless final_hash.values.last == value end final_array << final_hash end final_array end hope helps!
Comments
Post a Comment