Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code_Snippets_From_General_Assembly
# Ruby_Arrays
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
days.pop
days.unshift("Sunday")
puts days
============================================================================
Write code that would add the number 7 to "Erik's" favorite numbers.
users = {
"Jonathan" => {
:twitter => "tronathan",
:favorite_numbers => [12, 42, 75],
},
"Erik" => {
:twitter => "sferik",
:favorite_numbers => [8, 12, 24],
},
"Tripta" => {
:twitter => "triptagupta",
:favorite_numbers => [12, 14, 85],
},
}
# users["Erik"][:favorite_numbers] << (8000) Alternate_Answer using "<<"
users["Erik"][:favorite_numbers].push(100)
puts users
============================================================================
Write code that would add yourself to the users hash.
users = {
"Jonathan" => {
:twitter => "tronathan",
:favorite_numbers => [12, 42, 75],
},
"Erik" => {
:twitter => "sferik",
:favorite_numbers => [8, 12, 24],
},
"Tripta" => {
:twitter => "triptagupta",
:favorite_numbers => [12, 14, 85],
},
}
users["Jackson"] = {:twitter => "Tweet", :favorite_numbers => [10, 20]}
users["Daniel"] = {:facebook => "Face", :favorite_numbers => [1000, 200]}
puts users
============================================================================
Write code that returns the array of "Erik's" favorite numbers.
users = {
"Jonathan" => {
:twitter => "tronathan",
:favorite_numbers => [12, 42, 75],
},
"Erik" => {
:twitter => "sferik",
:favorite_numbers => [8, 12, 24],
},
"Tripta" => {
:twitter => "triptagupta",
:favorite_numbers => [12, 14, 85],
},
}
puts users["Erik"][:favorite_numbers]
============================================================================
Write code that returns the smallest of "Erik's" favorite numbers.
users = {
"Jonathan" => {
:twitter => "tronathan",
:favorite_numbers => [12, 42, 75],
},
"Erik" => {
:twitter => "sferik",
:favorite_numbers => [8, 12, 24],
},
"Tripta" => {
:twitter => "triptagupta",
:favorite_numbers => [12, 14, 85],
},
}
puts users["Erik"][:favorite_numbers].min
============================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment