Giter Site home page Giter Site logo

hash-chapter's Introduction

Ruby Practice

Run your Ruby file by typing ruby and then the name of the file you want to run in the Terminal.

If we want to run hash_person.rb, we can write the command:

ruby hash_person.rb

To re-run this command, you can use the UP and DOWN arrow keys to look at the history of commands you've run in a Terminal.

Hash

hash_person.rb

Input:

Maude 24 Artist

Key output: { :name => "Maude", :age => 24, :occupation => "Artist" }

Complete input and output example:

"Enter a name, age, and occupation separated by spaces:"
Maude 24 Artist
{ :name => "Maude", :age => 24, :occupation => "Artist" }
Make sure the value of the :age key is an Integer

hash_dig.rb

Write a program that uses the sample_hash variable and prints the value of key "history"

sample_hash = {
   :class => { 
      :student => { 
         :name => "Mike",
         "marks" => { 
            "physics" => 70,
            "history" => 80
         }
      }
   }
}

hash_find_value.rb

Write a program that: Asks the user for an Integer, then checks to see if that integer is a value of any of the keys in sample_hash. If you find the number, print out "100 is under the key: a." If you don't find the number print out "Could not find the integer 100"

Example:

"Enter an integer:"
4
"Could not find the integer 4"

hash_list.rb

Given this list of people, print only names of people who are at least 16.

Yes, you could just look at it with your eyes and print their names, but imagine that you couldn't because there are a million items in the list.

Use the variable, loops, and conditionals instead.

Output something like:

"Jerry"
"Sloane"
"Hurly"

Specs

Click here to see names of each test

hash_person.rb prints Hash of '{:name => "Osi", :age => 24, :occupation => "Songwriter"}', when input is 'Osi 24 Songwriter'

hash_person.rb prints Hash of '{:name => "Lia", :age => 32, :occupation => "Engineer"}', when input is 'Lia 32 Engineer'

hash_find_value.rb prints Hash of 'Could not find the integer 4', when input is '4'

hash_find_value.rb prints Hash of '100 is under the key: a.', when input is '100'

hash_find_value.rb prints Hash of '22 is under the key: e.', when input is '22'

hash_find_value.rb prints Hash of '32 is under the key: e.', when input is '32'

hash_dig.rb prints '80' by retriving the value from the Hash

hash_list.rb prints 'James', 'Yolanda', 'Red', and 'Fatimah' using variables, loops, if statements, and Hash methods'

hash-chapter's People

Contributors

jelaniwoods avatar iblash avatar bpurinton avatar pmckernin 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.