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' | |
| require 'pp' | |
| @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) | |
| match = string.match(/\b\d{3}\-\d{3}\-\d{3}\b/) | |
| !!match | |
| 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 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 | |
| puts @duration = end_time - start_time | |
| 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" | |
| @player1_points = 3 | |
| @player2_points = 3 | |
| @players = {player1: @player1_points, player2: @player2_points}.cycle | |
| def whos_playing | |
| puts "#{@current_player[0]}, your turn" |
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'] | |
| def average(numbers) |
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 | |
| puts "Tell me something" | |
| phrase = gets.chomp | |
| result = phrase.scan(/\w/) | |
| hash = Hash.new(0) | |
| result.inject(hash) {|key, value| | |
| hash[value] += 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
| @states = { | |
| OR: 'Oregon', | |
| FL: 'Florida', | |
| CA: 'California', | |
| NY: 'New York', | |
| MI: 'Michigan', | |
| } | |
| @states.store(:NJ,'New Jersey') | |
| @states.store(:AL,'Alabama') |
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
| =begin | |
| # Sort the array from lowest to highest | |
| def sort(arr) | |
| arr.sort | |
| end | |
| =end | |
| def bubble_sort(arr) | |
| n = arr.length |
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?(baller, furnished, rent) | |
| if baller && (furnished || rent < 2100) | |
| return true | |
| else | |
| return false | |
| 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
| def maximum(arr) | |
| n = arr.length | |
| loop do | |
| swapped = false | |
| (n-1).times do |i| | |
| if arr[i] > arr[i+1] | |
| arr[i], arr[i+1] = arr[i+1], arr[i] | |
| swapped = true | |
| end |