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
puts "hello" | |
"Benjamin".reverse | |
puts "Hi, {#name}" | |
def say_hi | |
print "What is your name: " | |
name = gets.chomp | |
puts "Hi, #{name}" | |
say_hi | |
def say_hello | |
puts "Hello, Ben" |
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(startNum,endNum) | |
startNum.upto(endNum) do |i| | |
if i % 5 == 0 && i % 3 == 0 | |
puts "FizzBuzz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
else | |
puts i |
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, rent, baller) | |
baller && (furnished || rent < 2100) ? true : false | |
end | |
### | |
# Add your "test" ("driver") code below in order to "test drive" (run) your method above... | |
# The test code will call the method with different permutations of options and output the result each time. | |
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works. | |
# Without the test code, it will be hard for you to know if this method is working as it should or not. | |
### |
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
def BubbleSort(to_sort) | |
n = to_sort.length | |
sorted = false | |
until sorted | |
sorted = true | |
for i in 0..(n - 2) | |
if to_sort[i] > to_sort[i + 1] | |
sorted = false |
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 BubbleSort(to_sort) | |
n = to_sort.length | |
sorted = false | |
until sorted | |
sorted = true | |
for i in 0..(n - 2) | |
if to_sort[i] > to_sort[i + 1] | |
sorted = false |
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 fizz_buzz(num_start,num_stop) | |
num_start.upto(num_stop) { |num| | |
puts evaluate(num) | |
} | |
end | |
def evaluate(num) | |
if div_3?(num) && div_5?(num) | |
"FizzBuzz" | |
elsif div_5?(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
def average(numbers) | |
sum = 0 | |
numbers.each do |num| | |
sum += num | |
end | |
if numbers.empty? || numbers.nil? | |
0 | |
else | |
sum / numbers.size | |
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
### 1. Tells the Numbers of Characters | |
def count_letters(string) | |
array = string.delete(" ").split("") | |
hash = Hash.new(0) | |
array.each do |letter| | |
letter = letter.downcase | |
hash[letter] += 1 | |
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
$states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} | |
#1. adding new states to state hash | |
$states[:TX] = 'Texas' |
OlderNewer