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 'active_support/all' | |
@candidates = [ | |
{ | |
id: 5, | |
years_of_experience: 4, | |
github_points: 293, | |
languages: ['C', 'Ruby', 'Python', 'Clojure'], | |
date_applied: 5.days.ago.to_date, | |
age: 26 |
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
#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) | |
if string.match(/\b(\d{3}-\d{3}-\d{3})\b/) | |
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
def benchmark | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
run_time = end_time - start_time | |
return run_time | |
end | |
long_string = "apple"*100000000 | |
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 to_roman(num) | |
#this mess takes the number, puts each digit in an array as an int | |
#and then reverse the array... why, you ask? because I'm lazy. | |
#this way I can then deal with the smallest numbers first, thus | |
#removing the need to know the length of num ahead of time. | |
#or something. i'm sure there are better ways. | |
num_arr = [] | |
while num > 0 | |
num_arr.unshift num % 10 |
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', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} | |
states[:DS] = "Distress" | |
states[:DR] = "Disrepair" |
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
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'] | |
#because hash does not use index |
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
#I had a 24 line version, but the assignment seems to request more than one method. | |
go = true | |
while go | |
#could be a method, but really no need to | |
#since it always has to happen | |
puts "> " | |
speak = gets.chomp.downcase | |
#had this in the main method, but this works too | |
def continue(speak) |
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
last = rand(1..100) | |
start = rand(1..last) | |
def fizzbuzz(start,last) | |
start.upto(last) do |i| | |
if i % 5 == 0 && i % 3 == 0 | |
puts "FizzBuzz" | |
elsif i % 5 == 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
# Find the maximum | |
def maximum(arr) | |
largest = arr[0] | |
arr.each do |i| | |
if i > largest | |
largest = i | |
end | |
end | |
return largest | |
end |