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
Joshua-Strubs-MacBook-Pro:~ joshuastrub$ cd lighthouse | |
Joshua-Strubs-MacBook-Pro:lighthouse joshuastrub$ irb | |
irb(main):001:0> def say_hi(name) | |
irb(main):002:1> "Hi, #{name}" | |
irb(main):003:1> end | |
=> nil | |
irb(main):004:0> say_hi("Josh") | |
=> "Hi, Josh" | |
irb(main):005:0> my_array = [5, 3, 5] | |
=> [5, 3, 5] |
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 bubble_sort(array) | |
n = array.length | |
swapped = false | |
(n-1).times do |i| | |
if array[i] > array[i + 1] | |
array[i], array[i + 1] = array[i + 1], array[i] | |
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 rent?(baller, furnished, rent) | |
baller && (furnished || rent < 2100) | |
end | |
puts rent?(true, true, 2200) |
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(x,y) | |
(x..y).each do |i| | |
case | |
when i % 15 == 0 then puts "FizzBuzz" | |
when i % 3 == 0 then puts "Fizz" | |
when i % 5 == 0 then puts "Buzz" | |
when i % 7 == 0 then puts "Fizzzzzzz" | |
else | |
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
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'} | |
# Why is it returning nil instead of first element of the list above | |
puts list.first |
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 | |
puts list.first |
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[:NC] = 'North Carolina' | |
@states[:CO] = '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
# 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}.\d{3}.\d{3})\b/.match(string) | |
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 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
def count_letters(str) | |
data = {} | |
str.split('').each do |l| | |
puts l | |
next if l == ' ' | |
if data[l].nil? | |
data[l] = 1 | |
else | |
data[l] += 1 | |
end |
OlderNewer