joshmfrankel / joshfrankel.me

Repo for my portfolio website
joshfrankel.me
0 stars 0 forks source link

How to map a nested array of hashes structure? #10

Open joshmfrankel opened 2 months ago

joshmfrankel commented 2 months ago

flat_map into #map

data = [{"id"=>"first-schedule-id", "type"=>"schedule", "name"=>"First Line of defense", "desciption"=>nil, "users"=>[{"id"=>"this-user-is-on-a-schedule"}, {"id"=>"non-matching-id"}]}, {"id"=>"just-another-schedule", "type"=>"schedule", "name"=>"Yolo", "desciption"=>nil, "users"=>[{"id"=>"another-non-matching"}]}]

# Extracting user ids
user_ids = data.flat_map { |entry| entry["users"].map { |user| user["id"] } }