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
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 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
# 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[0-9]{3}-[0-9]{3}-[0-9]{3}\b/.match(string) != nil | |
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 | |
puts "has_sin? returns false if it doesn't have a SIN" |
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 benchmark | |
# Your benchmarking code goes here. | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
end_time - start_time | |
end | |
# Be careful, pasting this into IRB will take a long time to print. |
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 recycle_bottle (full,empty,caps) | |
b = ((full + empty) / 2).floor | |
c = ((full + caps) / 4).floor | |
@fromB += b | |
@fromC += c | |
empty = (full + empty) % 2 |
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
require "pry-byebug" | |
def to_roman(num) | |
roman = ['','','M','D','C','L','X','V','I'] | |
array = num.to_s.each_char.map(&:to_i) | |
result = "" | |
array.each_with_index do |item,index| | |
result += one_digit(item,roman.slice(index*2,3)) | |
end | |
result | |
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
require "pry-byebug" | |
@states = { | |
OR: ['Oregon',['Salem', 'Portland']], | |
FL: ['Florida',['Tallahassee','Jacksonville']], | |
CA: ['California',['Sacramento','Los Angeles']], | |
NY: ['New York',['Albany','New York']], | |
MI: ['Michigan',['Lansing', 'Detroit']], | |
WA: ['Wahsington',['Olympia','Seattle']], | |
IN: ['Indiana',['Boise']] | |
} |
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_letters(str) | |
# count={} | |
# str.strip.each_char do |char| | |
# count[char] = 0 unless count.include?(char) | |
# count[char] += 1 | |
# end | |
# count | |
# end | |
def count_letters(str) |
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
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"] |
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 merge_sort(arr) | |
return arr if arr.length <=1 | |
left = [] | |
right = [] | |
arr.each_index do |index| | |
index.odd? ? left.push(arr[index]) : right.push(arr[index]) | |
end | |
left = merge_sort(left) | |
right = merge_sort(right) |
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 get_quote(dimensions, colour) | |
(dimensions * 15 + (colour > 2 ? colour * 15 : colour * 10))*1.15 | |
end | |
puts "#{get_quote(10, 3)}" |