Giter VIP home page Giter VIP logo

ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-nyc-web-100719's Introduction

NYC Pigeon Organizer

Learning Goals

  • Iterate over nested hashes
  • Sort and manipulate hashes

Introduction

Being able to navigate data is a critical programming skill. Sometimes, data we need isn't in an ideal structure and we need to reorganize it. In this lab, we'll be doing just that - taking a hash, reorganizing the data, and returning that newly structured data as a new hash.

Instructions

NYC Pigeon

You are helping a research group study pigeons in New York City. You are given the following collected data on New York City pigeons in the form of a hash:

pigeon_data = {
  :color => {
    :purple => ["Theo", "Peter Jr.", "Lucky"],
    :grey => ["Theo", "Peter Jr.", "Ms. K"],
    :white => ["Queenie", "Andrew", "Ms. K", "Alex"],
    :brown => ["Queenie", "Alex"]
  },  
  :gender => {
    :male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"],
    :female => ["Queenie", "Ms. K"]
  },
  :lives => {
    "Subway" => ["Theo", "Queenie"],
    "Central Park" => ["Alex", "Ms. K", "Lucky"],
    "Library" => ["Peter Jr."],
    "City Hall" => ["Andrew"]
  }
}

The data above is organized by attributes - :color, :gender, and :lives, each a hash. Within these hashes are arrays of pigeon names.

We want this data, but in a different structure. Rather than sorting by attributes, your task is to create a hash where pigeon names are the keys, with each name pointing to a hash of their attributes.

Iterate over the hash above, collecting each pigeon by name and insert it as the key of a new hash. Each of these hashes should have :color, :gender, and :lives keys assigned to arrays of info about that particular pigeon. Your output should look something like the hash below:

pigeon_list = {
  "Theo" => {
    :color => ["purple", "grey"],
    :gender => ["male"],
    :lives => ["Subway"]
  },
  "Peter Jr." => {
    :color => ["purple", "grey"],
    :gender => ["male"],
    :lives => ["Library"]
  },
  "Lucky" => {
    :color => ["purple"],
    :gender => ["male"],
    :lives => ["Central Park"]
  },
  "Ms. K" => {
    :color => ["grey", "white"],
    :gender => ["female"],
    :lives => ["Central Park"]
  },
  "Queenie" => {
    :color => ["white", "brown"],
    :gender => ["female"],
    :lives => ["Subway"]
  },
  "Andrew" => {
    :color => ["white"],
    :gender => ["male"],
    :lives => ["City Hall"]
  },
  "Alex" => {
    :color => ["white", "brown"],
    :gender => ["male"],
    :lives => ["Central Park"]
  }
}

Write your code in the provided nyc_pigeon_organizer method. The tests in this lab will use this method, passing in the original pigeon_data hash. Use learn and the test results to guide your progress.

Alternate Data Set

The goal here is to implement a process for converting any hash data that is in the original structure. The final tests in this lab use a alternate set of data to specifically test for this:

pigeon_data = {
  :color => {
    :brown => ["Luca"],
    :black => ["Lola"],
  },
  :gender => {
    :male => ["Luca"],
    :female => ["Lola"]
  },
  :lives => {
    "Central Park" => ["Lola"],
    "Library" => ["Luca"]
  }
}

Even though the names are different, the hash follows the same format as our original pigeon_data, so passing this hash into the nyc_pigeon_organizer should result in a new hash with "Luca" and "Lola" as the top level keys, pointing to hashes with their particular attributes.

Conclusion

Building programs requires data. Whether it is a set of numbers, user input, account information, or info scraped from websites, we need data to make our programs useful. Data, however, is not always organized in the way we want it. Being able to reorganize our data to make it even more useful is a skill we you will frequently use as you build more and more complex applications.

View NYC Pigeon Organizer on Learn.co and start learning to code for free.

ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-nyc-web-100719's People

Contributors

jongrover avatar kthffmn avatar loganhasson avatar maxwellbenton avatar aviflombaum avatar ahimmelstoss avatar sarogers avatar fislabstest avatar gilmoursa avatar fs-lms-test-bot avatar deniznida avatar euticus avatar drakeltheryuujin avatar stephaniecoleman avatar vibraniumforge avatar victhevenot avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.