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
#require "pry" | |
# Determine whether a string contains a SIN (Social Insurance Number). | |
# A SIN is 9 digits and we are assuming that they must have dashes in them | |
def has_sin?(string) | |
/\b(\d{3}-){2}\d{3}\b/ =~ string ? true : false | |
end | |
puts "has_sin? returns true if it has what looks like a SIN" | |
puts has_sin?("please don't share this: 234-604-142") == true |
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
states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
TX: 'Texas', | |
NY: 'New York' | |
} | |
# task1 ///// | |
states[:OG] = 'Oregon' | |
states[:COLO] = 'Colorado' |
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 count_letters(list) | |
variable = Hash.new | |
list.each do |word| | |
word.split('').each do |letter| | |
variable[letter] = variable[letter].nil? ? 1 : variable[letter] + 1 | |
end | |
end | |
variable | |
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
///// DEBUG 01 ///// -------------------- | |
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'} | |
# Why is it returning nil instead of first element of the list above | |
p list['yvr'] | |
///// DEBUG 02 ///// ------------------- | |
def average(numbers) |
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 bubblesort(arr) | |
n = arr.length | |
loop do | |
swapped = false | |
(n-1).times do |i| | |
if arr[i-1] > arr[i] | |
then arr[i-1], arr[i] = arr[i], arr[i-1] | |
swapped = true | |
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
def shakil_the_dog | |
puts "Your with shakil" | |
puts "Say something" | |
carryon = true | |
while carryon | |
userInput = gets.chomp.downcase | |
case userInput | |
when "woof" | |
puts "WOOF"*3 |
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) | |
(baller && rent < 2100) || (baller && furnished) | |
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 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_value(i) | |
if i % 5 == 0 && i % 3 == 0 | |
"FizzBuzz" | |
elsif i % 5 == 0 | |
"Buzz" | |
elsif i % 3 == 0 | |
"Fizz" | |
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
# Find the maximum | |
def maximum(arr) | |
maxNumber = arr[0] | |
arr.each do |item| | |
if item > maxNumber | |
end | |
end | |
return maxNumber | |
end | |
# expect it to return 42 below |