Question: In Ruby, create a hash of a hash map with the total occurrences of key values to output in a JSON style as shown. require
In Ruby, create a hash of a hash map with the total occurrences of key values to output in a JSON style as shown.
require 'json'
require csv
def mydataprocessstr
arr strsplit
index
values
while index arr.length
valuesindex arrindexsplit;
index
end
# count occurrances of Gender: Male Female Email, Age, City, Device, Order At
# create map with totals
arrmap
arrmap:Gender :Male :Female
arrmap:Email :domain :domain
arrmap:Age :a :b :c
arrmap:City :Male :Female
arrmap:Device :Male :Female
arrmap:"Order At :Male :Female
json JSON.prettygeneratearrmap
s json.gsub
sdelete!
s
end
mydataprocessGenderFirstName,LastName,UserName,Email,Age,City,Device,Coffee Quantity,Order At "Male,Carl,Wilderman,carl,yahoo.com,Seattle,Safari iPhone,afternoon", "Male,Marvin,Lind,marvin,hotmail.com,Detroit,Chrome Android,afternoon", "Female,Shanelle,Marquardt,shanelle,hotmail.com,Las Vegas,Chrome,afternoon", "Female,Lavonne,Romaguera,lavonne,yahoo.com,Seattle,Chrome,morning", "Male,Derick,McLaughlin,derick,hotmail.com,Chicago,Chrome Android,afternoon"
# Input: GenderFirstName,LastName,UserName,Email,Age,City,Device,Coffee Quantity,Order At "Male,Carl,Wilderman,carl,yahoo.com,Seattle,Safari iPhone,afternoon", "Male,Marvin,Lind,marvin,hotmail.com,Detroit,Chrome Android,afternoon", "Female,Shanelle,Marquardt,shanelle,hotmail.com,Las Vegas,Chrome,afternoon", "Female,Lavonne,Romaguera,lavonne,yahoo.com,Seattle,Chrome,morning", "Male,Derick,McLaughlin,derick,hotmail.com,Chicago,Chrome Android,afternoon"
#
# Expected Output return:
# Gender:Male:"Female":"Email":yahoocom":"hotmail.com":"Age"::::"City":Seattle:"Detroit":"Las Vegas":"Chicago":"Device":Safari iPhone":"Chrome Android":"Chrome":"Order At:afternoon:"morning":
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
