forked from appdev-projects/ruby-project-hash-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request appdev-projects#1 from appdev-projects/bp-additions
Bp additions
- Loading branch information
Showing
11 changed files
with
177 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"emmet.includeLanguages": { | ||
"erb": "html" | ||
}, | ||
"files.associations": { | ||
"*.erb": "erb" | ||
} | ||
} | ||
"editor.tabSize": 2, | ||
"emmet.includeLanguages": { | ||
"erb": "html" | ||
}, | ||
"files.associations": { | ||
"*.erb": "erb" | ||
}, | ||
"files.exclude": { | ||
"**/.git": true, | ||
".vscode": true, | ||
".bundle": true, | ||
".*": true, | ||
"*.ru": true, | ||
"Dockerfile": true, | ||
"Gem*": true, | ||
"install-packages": true, | ||
"main.rb": true, | ||
"README.md": true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,3 @@ | ||
# 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: | ||
|
||
```bash | ||
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: | ||
```bash | ||
"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" | ||
```ruby | ||
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: | ||
```bash | ||
"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: | ||
```bash | ||
"Jerry" | ||
"Sloane" | ||
"Hurly" | ||
``` | ||
## Specs | ||
<details> | ||
<summary>Click here to see names of each test</summary> | ||
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' | ||
</details> | ||
This project is associated with the [`Hash` chapter](https://firstdraft.github.io/appdev-textbook/hash-chapter.html). The steps to open and run a GitPod project can be found [here](https://firstdraft.github.io/appdev-textbook/string.html#start-gitpod-project). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
# ~~~~~ Specs (make it do these things) ~~~~~ | ||
# | ||
# dig.rb prints '80' by retriving the value from the Hash | ||
# | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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 (`4` is the input): | ||
# | ||
# "Enter an integer:" | ||
# 4 | ||
# "Could not find the integer 4" | ||
|
||
|
||
sample_hash = {:a => 100, :b => 200, :c => 300, :d => 400, :e => rand(200), :f => 600, :g => 0 } | ||
|
||
p "Enter an integer to find:" | ||
|
||
|
||
# ~~~~~ Specs (make it do these things) ~~~~~ | ||
# | ||
# find_value.rb prints Hash of 'Could not find the integer 4', when input is '4' | ||
# | ||
# find_value.rb prints Hash of '100 is under the key: a.', when input is '100' | ||
# | ||
# find_value.rb prints Hash of '22 is under the key: e.', when input is '22' | ||
# | ||
# find_value.rb prints Hash of '32 is under the key: e.', when input is '32' | ||
# | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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. | ||
# | ||
# Print each name on a new line, like: | ||
# | ||
# James | ||
# Yolanda | ||
# etc. | ||
|
||
list_of_people = [ | ||
{ :name => "James", :age => 16 }, | ||
{ :name => "Lee", :age => 12 }, | ||
{ :name => "Yolanda", :age => 26 }, | ||
{ :name => "Mel", :age => 15 }, | ||
{ :name => "Red", :age => 38 }, | ||
{ :name => "Fatimah", :age => 31 }, | ||
{ :name => "Carl", :age => 9 }, | ||
] | ||
|
||
|
||
# ~~~~~ Specs (make it do these things) ~~~~~ | ||
# | ||
# list.rb prints 'James', 'Yolanda', 'Red', and 'Fatimah' using variables, loops, if statements, and Hash methods' | ||
# | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Ask for a name, age, and occupation; store the | ||
# values in a Hash; display the Hash. | ||
# | ||
# Example: | ||
# | ||
# "Enter a name, age, and occupation separated by spaces:" | ||
# Maude 24 Artist | ||
# { :name => "Maude", :age => 24, :occupation => "Artist" } | ||
# | ||
# Hint: Make sure the value of the :age key is an Integer | ||
|
||
p "Enter a name, age, and occupation separated by spaces:" | ||
|
||
|
||
# ~~~~~ Specs (make it do these things) ~~~~~ | ||
# | ||
# person.rb prints Hash of '{:name => "Osi", :age => 24, :occupation => "Songwriter"}', when input is 'Osi 24 Songwriter' | ||
# | ||
# person.rb prints Hash of '{:name => "Lia", :age => 32, :occupation => "Engineer"}', when input is 'Lia 32 Engineer' | ||
# | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Oops, something went wrong.