Skip to content

Instantly share code, notes, and snippets.

View gist:4488e6a3f355fbd9eca6
# 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
View gist:3dee77c7cc8a9b6869db
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
@Andsbf
Andsbf / gist:464e9486260374f34899
Created Mar 3, 2015
FizzBuzz Refactor Exercise
View gist:464e9486260374f34899
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
View Sign shop exercise
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
@Andsbf
Andsbf / The Yuppie Vancouverite
Created Mar 4, 2015
The Yuppie Vancouverite Exercise
View The Yuppie Vancouverite
# 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
@Andsbf
Andsbf / Personal Sort array + benchmark test
Last active Aug 29, 2015
Sort array (Bubble sort) Exercise
View Personal Sort array + benchmark test
# # 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
@Andsbf
Andsbf / Shakil The Dog
Created Mar 4, 2015
Exercise Shakil The Dog
View Shakil The Dog
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
View debug01.rb
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
@Andsbf
Andsbf / to_roman.rb
Created Mar 5, 2015
Roman Numerals Exercise
View to_roman.rb
require 'pry'
# require 'pry-nav'
def to_roman(num)
@roman_num = ""
@num = num
roman_M(@num)
roman_D(@num)
roman_C(@num)
roman_L(@num)
@Andsbf
Andsbf / state_info.rb
Created Mar 5, 2015
States & Cities Exercise
View state_info.rb
# require 'pry'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:OK] = "OKlahoma"