Skip to content

Instantly share code, notes, and snippets.

[1] pry(main)> def say_hi(name)
[1] pry(main)* "Hi #{name}"
[1] pry(main)* end
=> :say_hi
[2] pry(main)> say_hi("Shino")
=> "Hi Shino"
[3] pry(main)> my_number = 23
=> 23
[4] pry(main)> my_array = [1,25,61,2]
=> [1, 25, 61, 2]
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
if baller && furnished || rent < 2100
return true
else
return false
end
end
###
@shinobcrc
shinobcrc / sort.rb
Last active June 22, 2016 01:57 — forked from davidvandusen/sort.rb
# # Sort the array from lowest to highest
# def sort(arr)
# arr.sort
# end
def bubble_sort(array)
#n = total number of values in array
n = array.length
loop do
@shinobcrc
shinobcrc / max.rb
Last active June 22, 2016 02:59 — forked from davidvandusen/max.rb
# Find the maximum
def maximum(array)
max = array[0]
array.each do |x|
if max < x
max = x
end
end
max
@shinobcrc
shinobcrc / fizzbuzz.rb
Last active June 22, 2016 02:59
fizzbuzz
def fizzbuzz(max)
(1..max).each do |i|
if i % 15 == 0
puts "FizzBuzz"
elsif i % 5 == 0
puts "Buzz"
elsif i % 3 == 0
puts "Fizz"
else
puts i
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
def shakil_the_dog
@shinobcrc
shinobcrc / fizzbuzz_messy.rb
Last active June 22, 2016 03:35 — forked from kvirani/fizzbuzz_messy.rb
W1D2 Homework Exercise - Ruby - Messy Fizzbuzz
def fizzbuzz(s, f)
s.upto(f) { |x| puts e(x) }
end
def e(number)
if div_3?(number) && div_5?(number)
"FizzBuzz"
elsif div_5?(number)
"Buzz"
elsif div_3?(number)
list = {
'yvr' => 'Vancouver',
'yba' => 'Banff',
'yyz' => 'Toronto',
'yxx' => 'Abbotsford',
'ybw' => 'Calgary'
}
# Why is it returning nil instead of first element of the list above
@shinobcrc
shinobcrc / count_letters.rb
Created June 22, 2016 14:32
Character count and Index locater
def count_letters(list)
letters = Hash.new(0)
list.each do |word|
word.split('').each { |letter| letters[letter] += 1 }
end
letters
end
my_array = ['lighthouse', 'in', 'the', 'house']
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:GA] = "Georgia"