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
2.2.1 :001 > def say_hi(name) | |
2.2.1 :002?> "Hi, #{name}" | |
2.2.1 :003?> end | |
=> :say_hi | |
2.2.1 :004 > say_hi("stu") | |
=> "Hi, stu" | |
2.2.1 :005 > my_array = [4, 7, 1, 0] | |
=> [4, 7, 1, 0] | |
2.2.1 :006 > my_array.sort | |
=> [0, 1, 4, 7] |
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) | |
# arr.max | |
# end | |
def number(arr) | |
a = "".to_i | |
arr.each do |b| | |
if a < b | |
a = b |
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(a, b) | |
a.upto(b) do |i| | |
if i % 5 == 0 && i % 3 == 0 | |
puts "FizzBuzz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
elsif i % 3 == 0 | |
puts "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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(baller, furnished, rent) | |
if (baller && furnished) || rent < 2100 | |
puts true | |
else | |
puts 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
# Save this file to your computer so you can run it | |
# via the command line (Terminal) like so: | |
# $ ruby shakil_the_dog.rb | |
# | |
# Your method should wait for user input, which corresponds | |
# to you saying something to your dog (named Shakil). | |
# You'll probably want to write other methods, but this | |
# encapsulates the core dog logic | |
# def shakil_the_dog |
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 sort(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 |
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 sign_order | |
puts "How many square feet is your sign?" | |
size = gets.chomp.to_i | |
subtotal_1 = size * 15 | |
puts "How many colours would you like?" | |
colours = gets.chomp.to_i | |
if colours <= 2 | |
subtotal_2 = colours * 10 | |
else | |
subtotal_2 = colours * 15 |
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
1. | |
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'] | |
2. | |
def average(numbers) | |
sum = 0 | |
numbers.each do |num| |
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' | |
def count_letters(string) | |
letter_hash = Hash.new(0) | |
# string.each do |chars| | |
string.split('').each do |i| | |
letter_hash[i] += 1 | |
end | |
# end | |
letter_hash |
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' | |
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} |
OlderNewer