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
describe 'mean' do | |
let(:array_1) { [1, 2, 3, 4, 5, 5, 7] } | |
let(:array_2) { [4, 4, 5, 5, 6, 6, 6, 7] } | |
it "is defined as a method" do | |
defined?(mean).should eq 'method' | |
end | |
it "requires a single argument" do | |
method(:mean).arity.should eq 1 |
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
# print_triangle(rows) prints out a right triangle of +rows+ rows consisting | |
# of * characters | |
# | |
# +rows+ is an integer | |
# | |
# For example, print_triangle(4) should print out the following: | |
# * | |
# ** | |
# *** | |
# **** |
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
#from stackoverflow, want to see if/how it works, not taking credit or will use if it does | |
def reverse_words(string) # Method reverse_string with parameter 'string'. | |
loop = string.length # int loop is equal to the string's length. | |
word = '' # This is what we will use to output the reversed word. | |
while loop > 0 # while loop is greater than 0, subtract loop by 1 and add the string's index of loop to 'word'. | |
loop -= 1 # Subtract 1 from loop. | |
word += string[loop] # Add the index with the int loop to word. | |
end # End while loop. | |
return word # Return the reversed word. | |
end # End the method. |
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 times_table(rows) | |
first_row = [] | |
int = 5 | |
1.upto(5) do |i| | |
first_row.push(i) | |
end | |
first_row |
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 super_fizzbuzz(array) | |
fizzbuzzed = [] | |
array.each do |num| | |
if num % 3 == 0 && num % 5 == 0 # return "FizzBuzz" | |
fizzbuzzed.push("FizzBuzz") | |
elseif num % 3 == 0 # return "Fizz" | |
fizzbuzzed.push("Fizz") | |
elseif num % 5 == 0 # return "Buzz" | |
fizzbuzzed.push("Buzz") |
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
# shortest_string is a method that takes an array of strings as its input | |
# and returns the shortest string | |
# +array+ is an array of strings | |
# shortest_string(array) should return the shortest string in +array+ | |
# If +array+ is empty the method should return nil | |
# array.sort.first | |
def shortest_string(array) | |
new_count = [ ] |