I need some help understanding the below ruby code.
counted = Hash.new(0)
parsed_reponse["result"]["data"].each { |h| counted[h["version"]] += 1 }
counted = Hash[counted.map {|k,v| [k,v.to_s] }]
- I understand line 1 creats a hash which I believe is similar to a dictionary in python.
- Line 2 loops through my json data set a adds a new key and value pair if none exits and increments the count if 1 does exist.
- What does the 3rd line do?
Hash[ [ [key, value], ... ] ] → new_hash-- Creates a new hash populated with the given objects.