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
# 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 |
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
#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) |
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
#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) |
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
# 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 | |
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
#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 |
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
def total (colornum, length, height) | |
@length = length | |
@colornum = colornum | |
@height = height | |
tax = 1.15 | |
if colornum <= 2 | |
(colornum*10 + length*height*15)*tax | |
else |
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
# 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 |
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
# 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 |
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
#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" |
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
#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 | |
OlderNewer