Skip to content

Instantly share code, notes, and snippets.

View charmainetham's full-sized avatar

Charmaine Tham charmainetham

View GitHub Profile
@charmainetham
charmainetham / MAX VALUE.rb
Last active April 27, 2016 02:02
Maximum Value
# Find the maximum
def maximum(arr)
# Setting the value as max value at first
max_value = arr.first
# For each value in the array the highest value would be x if x is higher than the first value
arr.each{|x| max_value = x if x > max_value}
max_value
end
#first prompting user
puts "what number would you like to start with"
start = gets.chomp
puts "what number would you like to end with?"
endd = gets.chomp
# Define the variables
(start.to_i..endd.to_i).each do |i|
divby5 = (i % 5 == 0)
divby3 = (i % 3 == 0)
@charmainetham
charmainetham / FIZZBUZZ.rb
Last active April 27, 2016 02:01
FIZZBUZZ
#first prompting user
puts "what number would you like to start with"
start = gets.chomp
puts "what number would you like to end with?"
endd = gets.chomp
# Define the variables
(start.to_i..endd.to_i).each do |i|
divby5 = (i % 5 == 0)
divby3 = (i % 3 == 0)
@charmainetham
charmainetham / renter.rb
Last active April 27, 2016 02:01
RENTER
# 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
#AFTER CODE REVIEW
def shakil_the_dog
response = nil
until (response == "go away")
puts "what would you like to say to Shakil?"
response = gets.chomp.downcase
case
def total (colornum, length, height)
@length = length
@colornum = colornum
@height = height
tax = 1.15
if colornum <= 2
(colornum*10 + length*height*15)*tax
else
# Sort the array from lowest to highest
def sort(arr)
# if the size of array is less than or 1 output that item
arrlen = arr.length
if arrlen <= 1
return arr
else
mid = arrlen/2 #finding the middle of the array
leftarr = arr[0..mid-1]#splitting it into the first half of the array
rightarr = arr[mid ..arrlen]#splitting it to second half of array up to the last index of the array
# Sort the array from lowest to highest
def sort(arr)
swap = false
until swap
swap = true
(arr.length - 1).times do |x|
if arr[x] > arr[x +1]
arr[x], arr[x+1] = arr[x+1], arr[x]
swap = false
end
@charmainetham
charmainetham / statesandcities.rb
Created April 28, 2016 02:53
States & cities
#code to find out about cities
@states = {
OR: "Oregon",
FL: "Florida",
CA: "California",
NY: "New York",
MI: "Michigan"
}
#Task 1 inserting 2 additional states without modifying initial hash
@states[:MO] = "Missouri"
@charmainetham
charmainetham / charcount.rb
Created April 28, 2016 02:55
Character counting
#Counting the number of letters
def count_letters(words)
count = Hash.new(0)
words.gsub(" ","").split('').each do |letters|
count[letters] += 1
end
count
end