Giter Site home page Giter Site logo

programming-univbasics-4-intro-to-hashes-lab-nyc-web-082619's Introduction

Intro to Hashes Lab

Learning Goals

  • Build simple hashes.
  • Access and modify data stored in a hash.
  • Add new data to a hash.

Introduction

It's time to practice what we've learned about Ruby hashes. In this lab, your task is to implement a set of methods. Each method will require you to complete some basic hash creation and modification. Use learn and follow the test suite messages as you work through your solution.

Instructions

Code your solution in the intro_to_ruby_hashes_lab.rb file located in the main directory of this lab.

  1. Create a method called new_hash that creates and returns a new, empty hash.

  2. Create a method called my_hash that returns a valid hash. This hash should have at least one key/value pair of your choice.

  3. Create a method called pioneer that returns a hash. This hash should have a key that is a symbol :name and whose value is a string, 'Grace Hopper'.

  4. Create a method called id_generator that creates and returns a hash with one key/value pair. The key should be a symbol, :id. For the value, provide a positive integer of your choice.

  5. Create a method called my_hash_creator that takes in two parameters. In this method, create and return a hash with one key/value pair, using the first parameter as the key, and the second parameter as the value.

  6. Create a method call read_from_hash that takes in two parameters. The first parameter is a hash, the second is a key. Used together, they will either produce a value on that hash corresponding to the key, or nil by default. Use these two parameters in conjunction to do just that.

  7. Create a method called update_counting_hash that takes in two parameters. The first parameter is a hash, and the second is a key. The hash provided will have any number of keys, but all values will be integers. The update_hash method should do one of two things: increment an existing value based on the provided key parameter, or create a new key/value pair using the provided key, setting the value to 1. So, for example, if we had the following hash:

{
  :apples => 3
}

..and a provided key, :apples, update_hash should return an updated hash:

{
  :apples => 4
}

However, if the hash was given a key that doesn't exist, like :oranges, it should return:

{
  :apples => 3,
  :oranges => 1
}

Conclusion

Hashes are an essential data type that we will use frequently. Now that you've seen the basics of creating, reading and updating hashes, we can explore some examples of more complicated hashes!

Resources

programming-univbasics-4-intro-to-hashes-lab-nyc-web-082619'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

Watchers

 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.