[ad_1]
I’m trying to sort the below object list by distance field. I’m having no success
here is the structure:
[{"id"=>13, "distance"=>"6612.9"},{"id"=>2, "distance"=>"512.9"},{"id"=>, "distance"=>"343.9"}]
here is the map
itemmap = items.map { |item| item.attributes.merge(distance: get_item_distance(item,[params[:latitude], params[:longitude]]).try(:round, 1) }
Then for sorting I tried the below method but non worked
itemmap.sort_by(&:distance)
itemmap.sort_by { |k, v| v[:distance] }
itemmap.map {|item| item.distance }
itemmap.sort_by {|item| item.distance}
[ad_2]