Git Product home page Git Product logo

uci-mod-3-hash-review-lab'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

Its 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

  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 #actor that returns a hash. This hash should have a key that is a symbol :name and whose value is a string, 'Dwayne The Rock Johnson'.

  4. Create a method called #read_from_hash that takes in two parameters. The first is a hash, and the second is a key. Use the provided key and bracket notation to access and return the corresponding value. For instance, if the following hash was passed in:

{
  name: "Sam",
  age: 31
}

...and the key provided was :age, this method should return 31.

  1. 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, generate a random number value using Ruby's built in rand method.

  2. 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.

  3. 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 a key data type that we will end up using frequently. Now that you've grasped the basics of creating, reading and updating hashes, we can explore some examples of more complicated hashes!

Resources

uci-mod-3-hash-review-lab's People

Contributors

ahimmelstoss avatar aviflombaum avatar deniznida avatar ehawk823 avatar fislabstest avatar fs-lms-test-bot avatar ga-be avatar markedwardmurray avatar maxwellbenton avatar msuzoagu avatar octosteve avatar pletcher avatar roseweixel avatar sarogers avatar sophiedebenedetto avatar victhevenot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.