Giter Club home page Giter Club logo

programming-univbasics-4-building-nested-hashes-nyc-web-012720's Introduction

Building Nested Hashes Lab

Learning Goals

  • Build a nested hash
  • Add key/value pairs in a nested hash
  • Update key/value pairs in a nested hash

Introduction

In this lab, we will practice constructing deeply-nested Hash. This means that we'll have a Hash that contains a Hash inside of it. Those "interior" or "inner" Hashes might themselves contain Hashes.

As a reminder, this might look like:

# Greatly abbreviated!
countries_and_capitals_of_the_world = {
  :north_america => {
    "Canada" => {
      :capital => "Ottawa",
      :capital_climate => "Kőppen Dfb"
    },
    "USA" => {
      :capital => "Washington D.C.",
      :capital_climate => "Kőppen Cfa"
    }
  },
  :africa => {
    "Ghana" => {
      :capital => "Accra",
      :capital_climate => "Kőppen Aw"
    },
    "Nigeria" => {
      :capital => "Abuja",
      :capital_climate => "Kőppen Aw"
    }
  }
}

We will work through this lab by filling out the implementation of four methods. Each method will return a Hash that is locally defined within that method's implementation. The comments in ./intro_to_ruby_hashes_lab.rb and the results of running the tests will guide you.

Process

We're going to write the implementation of 4 methods

  • base_hash
  • monopoly_with_second_tier
  • monopoly_with_third_tier
  • monopoly_with_fourth_tier

Between the different implementations, we'll build on the previous method's implementation. So the tests will guide you first to a Hash that passes base_hash's test.

Then, you should take the end successful Hash from base_hash and copy it into monopoly_with_second_tier. The monopoly_with_second_tier has some additional expectations so what you just copied won't quite work. The tests will guide you to getting it working. Repeat this process until your methods pass all the tests. If you get stumped, we've included the final Hash in the file final_hash.rb in this repository.

PATTERN FOR LEARNING: We've seen many students take the final answer and pare it down to get the tests passing. This is not a good path to mastering this concept. The path that requires work in programming, at the gym, or in relationships creates the most benefit.

Conclusion

Congratulations! You've built a pretty complex Hash with nesting. This should prove to you that there's very little in this world that can't be modeled with nesting of Hashes, scalar values, and Arrays.

Resources

programming-univbasics-4-building-nested-hashes-nyc-web-012720's People

Contributors

maxwellbenton avatar sophiedebenedetto avatar msuzoagu avatar deniznida avatar victhevenot avatar ahimmelstoss avatar aviflombaum avatar fs-lms-test-bot avatar pletcher avatar roseweixel avatar sarogers avatar octosteve avatar fislabstest avatar ehawk823 avatar ga-be avatar markedwardmurray 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.