Nested Data Structures

Wendyharris
1 min readApr 5, 2021

Complex nested data structures are things like Arrays of Arrays of Arrays, or Hashes of Arrays of Hashes. We get our raw data from our databases or provided by a third party. From there we’ll form a hypothesis to write our code and provide results, or insights from the results of our Nested Data Structure. Transforming that raw data into insights is one of a programmers essential role.

The four simplest nested data structures are an Array of Arrays AoA, Array of Hashes AoH, Hash of Arrays HoA, and Hash of Hashes HoH. Most of the syntax works exactly the same between Arrays of Arrays to Arrays of Hashes.

If you think about a contact list, it’s also easy to export it to a spreadsheet like a Google Sheet or an Excel Sheet. You could take the fields on the card and make them the columns across the top of the spreadsheet. Then for each member of the contact list you could make a new row for it. An Array of Hashes is well expressed by a contact list add some standard fields to it (first name, last name, phone number, email address, etc.) and fill the fields in, add to the list and then they go in an Array, an Array of Hashes.

contacts = [

{:first_name=> “Sylvia”, :last_name=> “Brett”, :phone_number=> “(897)873–9876”, :email=> sylviabrett@gmail.com}

{:first_name=> “Henry”, :last_name=> “Ring”, :phone_number=> “(327)345–2323”, :email=> henryring@gmail.com}

{:first_name=> “Sara”, :last_name=> “Smith”, :phone_number=> “(236)893–2376”, :email=> sylviabrett@gmail.com}

]

--

--