This file contains hidden or 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 sonny_says | |
puts "Sonny says:" | |
print "> " | |
@what_sonny_says = gets.chomp | |
end | |
def random_year_generator(starting_year, ending_year) | |
@random_year = rand(starting_year..ending_year) | |
end |
This file contains hidden or 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 sonny_says | |
puts "Sonny says:" | |
print "> " | |
what_sonny_says = gets.chomp | |
end | |
def random_year(year_range) | |
year = rand(year_range) | |
end | |
This file contains hidden or 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 find_and_replace(content, old_string, new_string) | |
@content_to_be_reset = content | |
if File.file?("#{content}") | |
@original_content = File.read("#{content}") | |
new_file_content = @original_content.gsub(old_string, new_string) | |
else | |
@original_content = content | |
new_file_content = @original_content.gsub!(old_string, new_string) | |
# gsub is better for testing purposes | |
# use gsub! if you want the string to retain its newly replaced content |
This file contains hidden or 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 reads_a_file(file) | |
files_content = File.read(file) | |
end | |
def character_count_with_spaces(file_string) | |
file_string.length | |
end | |
This file contains hidden or 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 reads_a_file(file) | |
File.read(file) | |
end | |
def character_count_with_spaces(file_string) | |
file_string.length | |
end | |
This file contains hidden or 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(num_range) | |
(num_range).each do |num| | |
if ( num % 3 == 0 ) && ( num % 5 == 0 ) | |
print 'FizzBuzz' | |
elsif num % 3 == 0 | |
print 'Fizz' | |
elsif num % 5 == 0 | |
print 'Buzz' | |
else | |
print num |
This file contains hidden or 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 reverse_word_order(string) | |
string.split(" ").reverse.join(" ") | |
end | |
blah = "Hi there John" | |
puts reverse_word_order(blah) |
This file contains hidden or 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 sums_an_array(arr) | |
sum = 0 | |
arr.each do |num| | |
sum += num | |
end | |
sum | |
end | |
collection = [1, 2, 3, 4, 5] | |
puts sums_an_array(collection) |
This file contains hidden or 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 odd_or_even(arr) | |
arr.each do |num| | |
print num | |
puts num % 2 == 0 ? ' is even' : ' is odd' | |
end | |
end | |
collection = [12, 23, 456, 123, 4579] | |
odd_or_even(collection) |
This file contains hidden or 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 quiz_completion_numbers(arr) | |
incomplete = [] | |
arr.each do |num| | |
( incomplete << num ) if ( num == 0 ) | |
end | |
"The number of participants who did not attempt Quiz 1 is #{incomplete.length} out of #{arr.length} total participants." | |
end | |
quiz = [0,0,0,1,0,0,1,1,0,1] | |
puts quiz_completion_numbers(quiz) |