A data structure is a group of data organized in the computer's memory by certain specific rules defining predictable relationships between the data. Arrays, hashes and relational databases are all examples of data structures.
This file contains hidden or 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
puts "Say Something to Grandma" | |
bye = 0 | |
while bye < 3 | |
reply = gets.chomp | |
if reply == "BYE" | |
bye += 1 | |
elsif reply == reply.upcase #condition, not variable put == | |
puts "No, not since #{rand(1930..1950)}" #string interpolation "#{variable}" #Use .. to do numbers inclusive (... exclusive | |
else |
This file contains hidden or 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
class Song | |
def booze (bottle, number) | |
@bottle = bottle | |
@number = number | |
end | |
def sing | |
while number != 0 | |
puts "#{number} Bottles of #{bottle} on the wall, #{number} bottles of #{bottle}, you take one down, pass it around #{number-1} bottles of #{bottle} on the wall" |
This file contains hidden or 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
#Using the array of hashes above, output the titles, along with their year to achieve the following output. | |
# 1998: The Big Lebowski | |
# 1980: The Shining | |
# 1990: Troll 2 | |
favorite_movies = [ | |
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 }, | |
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 }, | |
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 } |
This file contains hidden or 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
class GuessingGame | |
def initialize(guess) | |
$user_choice = guess | |
$comp_selection = rand(1...1000) | |
end | |
def numeric?(user_choice) | |
true if Float(user_choice) rescue false | |
end |
This file contains hidden or 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
def quick_sort(arr) | |
return arr if arr.length <= 1 | |
pivot = arr.pop | |
less_than_pivot = arr.select { |x| x < pivot } | |
greater_than_pivot = arr.select { |x| x > pivot } | |
quick_sort(less_than_pivot) + [pivot] + quick_sort(greater_than_pivot) | |
end | |
print quick_sort([1,5,9,2,45,2,3,4,4545]) |
This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or 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
# This index handler lets you navigate to the following routes: | |
#category_drinks | GET | /categories/:category_id/drinks(.:format) | drinks#index | |
# drinks | GET | /drinks(.:format) | drinks#index | |
# and... | |
def index | |
if params.include?('category_id') | |
category = Category.find(params[:category_id]) | |
@drinks = Drink.where(category: category).page(params[:page]) | |
else |
This file contains hidden or 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
.body-class { | |
min-height: 84%; | |
} |
This file contains hidden or 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
var d = new Date(1394648309130.185) | |
d // Wed Mar 12 2014 11:18:29 GMT-0700 (Pacific Daylight Time) | |
d.getTime() | |
// 1394648309130 // Fractions of a millisecond are dropped | |
OlderNewer