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
2.1.3 :003 > fun say_hi { | |
2.1.3 :004 > puts "Hi | |
2.1.3 :005"> } | |
2.1.3 :006"> | |
2.1.3 :007"> | |
2.1.3 :008"> | |
2.1.3 :009"> | |
2.1.3 :010"> "Bob" | |
2.1.3 :011"> | |
2.1.3 :012"> |
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
# Find the maximum | |
def maximum(arr) | |
max = arr[0] | |
arr.each { |x| max = x if x > max } | |
max | |
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 fizzbuzz(start, finish) | |
for x in start .. finish | |
if x % 3 == 0 | |
puts "Fizz" | |
elsif x % 5 == 0 | |
puts "Buzz" | |
else | |
puts x | |
end | |
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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(furnished, rent, baller) | |
baller && (furnished || rent < 2100) ? true : false | |
end | |
### | |
# Add your "test" ("driver") code below in order to "test drive" (run) your method above... | |
# The test code will call the method with different permutations of options and output the result each time. | |
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works. | |
# Without the test code, it will be hard for you to know if this method is working as it should or not. |
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 shakil_response(input) | |
case input | |
when"woof" | |
puts "WOOF " * 3 | |
when "shakil stop" || "Shakil STOP!" | |
puts "..." | |
when "meow" |
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
# Sort the array from lowest to highest | |
def sort(arr) | |
swaps = 1 | |
while(swaps != 0) | |
swaps = 0 | |
for index in 0 .. (arr.size - 2) | |
if arr[index] > arr[index + 1] | |
swaps++ | |
temp = arr[index] | |
arr[index] = arr[index + 1] |
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 colour_cost(colours) | |
num_colours = colours.size | |
num_colours > 2 ? 15 * num_colours : 10 * num_colours | |
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 count(string) | |
let_counts = {} | |
string.split(//).each { |let| let_counts[let] ? let_counts[let] += 1 : let_counts[let] = 1 } | |
let_counts | |
end | |
puts count("lea asdjflasdfl asidufoaubvoahboaeurfaw") | |
puts count ("maybe a better count zzzzzzz ooo") |
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
@numbers = { | |
M: 1000, | |
D: 500, | |
C: 100, | |
L: 50, | |
X: 10, | |
V: 5, | |
I: 1 | |
} |
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 describe_state(state_code) | |
first_part = "#{state_code} is for #{@states[state_code.to_sym]}.\ | |
It has #{@cities[state_code.to_sym].length} major cities:" | |
@cities[state_code.to_sym].each { |city| first_part << " #{city},"} | |
first_part.chomp(',') | |
end | |
def calculate_tax(state_code, amount) | |
if @taxes.keys.includes?(state_code.to_sym) | |
'%.2f' % (amount * (1 + @taxes[state_code.to_sym] / 100)).round(2) |
OlderNewer