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
vagrant [coding_ruby]> irb | |
2.1.3 :001 > quit | |
vagrant [coding_ruby]> pry | |
[1] pry(main)> def say_hi | |
[1] pry(main)* puts "input your name" | |
[1] pry(main)* name = gets.chomp | |
[1] pry(main)* puts "hi #{name}" | |
[1] pry(main)* end | |
=> :say_hi | |
[2] pry(main)> say_hi |
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 = 0) | |
#arr.max #Initial code (lighthouse code) | |
max_value = arr[0] | |
max_value = 0 if arr[0] == nil #Avoid empty array, makes answer zero | |
arr.each do |i| | |
max_value = i if (max_value <= i) | |
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 fizzBuzz(_start,_end) | |
_start.upto(_end) {|i| | |
puts "Fizz" if i%3 == 0 && i%5 != 0 | |
puts "Buzz" if i%3 != 0 && i%5 == 0 | |
puts "FizzBuzz" if i%3 == 0 && i%5 == 0 | |
puts i if i%3 != 0 && i%5 != 0 | |
} | |
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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(furnished, baller, rent) | |
baller && (furnished || rent < 2100) | |
# if baller && (furnished || rent < 2100) | |
# return puts true | |
# else | |
# return 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
def user_input | |
puts "what do you have to say to Shakil(dog):" | |
gets.chomp | |
end | |
def shakil_behavior(user_input) | |
user_input = "treat" if user_input.include? "treat" | |
case user_input |
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_Anderson(arr) | |
# arr.sort #initial code | |
flag =true | |
while flag | |
arr_before = arr.clone | |
arr = check_next(arr) | |
flag = false if arr_before == arr | |
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 get_dimension_price | |
while true | |
puts "Input banner width in m:" | |
width = gets.chomp.to_f | |
break if (width != 0.0 && width < 150) # avoid string input and unreasonable values=a banner bigger than 150m | |
end | |
puts "Input banner height in m:" | |
height = gets.chomp.to_f |
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' | |
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'} | |
binding.pry | |
# Why is it returning nil instead of first element of the list above | |
p 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
require 'pry' | |
def count_letters (string="") | |
counts = Hash.new(0) | |
string.split("").each do |element| | |
# binding.pry | |
counts[element] += 1 if element != " " | |
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
# require 'pry' | |
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} | |
@states[:TX] = "Texas" | |
@states[:OK] = "OKlahoma" |
OlderNewer