-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.c9/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,17 @@ | |
|
||
def longest_string(list) | ||
# This is your job. :) | ||
saved = list.first | ||
This comment has been minimized.
Sorry, something went wrong.
jcdavison
|
||
list.each do |item| | ||
if item.length > saved.length | ||
saved = item | ||
end | ||
end | ||
return saved | ||
This comment has been minimized.
Sorry, something went wrong. |
||
end | ||
|
||
if __FILE__ == $0 | ||
# I'd advise putting some sanity checks here. | ||
p longest_string(['Nina', 'school', 'outmost']) == 'outmost' | ||
# How else will you be sure your code does what you think it does? | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,14 @@ | |
|
||
def mean(list) | ||
total = sum(list) # This is the "sum" method from our sum.rb file | ||
# result = ____ # Given we have the sum of the list, how can we calculate the average? | ||
result = total/list.length # Given we have the sum of the list, how can we calculate the average? | ||
return result | ||
end | ||
|
||
if __FILE__ == $0 | ||
# I'd advise putting some sanity checks here. | ||
# How else will you be sure your code does what you think it does? | ||
p mean([Float(5), Float(2)]) == 3.5 | ||
This comment has been minimized.
Sorry, something went wrong.
jcdavison
|
||
p mean([5 , 5]) == 5.0 | ||
p mean([10, 20, 30]) == 20.0 | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,27 @@ | |
# ***** | ||
# ******* | ||
|
||
def print_line(count) | ||
(1..count).each do |i| # or, equivalently, for i in (1..count) | ||
print "*" # This prints a single "*" | ||
end | ||
end | ||
|
||
def print_line_of_spaces(count) | ||
(1..count).each do |i| # or, equivalently, for i in (1..count) | ||
print " " # This prints a single "*" | ||
end | ||
end | ||
|
||
def print_horizontal_pyramid(height) | ||
count = height | ||
(1..height).each do |r| | ||
This comment has been minimized.
Sorry, something went wrong.
jcdavison
|
||
count -= 1 | ||
print_line_of_spaces(count) | ||
print_line(r) | ||
print_line(r-1) | ||
print "\n" # This forces the output to the next like, like hitting "return" on the keyboard | ||
end | ||
end | ||
|
||
if __FILE__ == $0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,27 @@ def print_pyramid(height) | |
# This is your job. :) | ||
# Suggestion: you can call print_triangle to print out the first, "upward" half of the pyramid | ||
# You'll have to write code to print out the second, "downward" half of the pyramid. | ||
print_triangle(height) | ||
while height > 1 do | ||
This comment has been minimized.
Sorry, something went wrong.
jcdavison
|
||
height -=1 | ||
print_line(height) | ||
end | ||
end | ||
|
||
if __FILE__ == $0 | ||
# I'd advise putting some sanity checks here. | ||
# How else will you be sure your code does what you think it does? | ||
print_pyramid(1) | ||
|
||
print "\n\n\n" # This is here just to make the separation between triangles clearer | ||
|
||
print_pyramid(2) | ||
|
||
print "\n\n\n" # This is here just to make the separation between triangles clearer | ||
|
||
print_pyramid(3) | ||
|
||
print "\n\n\n" # This is here just to make the separation between triangles clearer | ||
|
||
print_pyramid(10) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
def word_count(string) | ||
# Hint: You'll want to use String#split | ||
# See: http://www.ruby-doc.org/core-2.1.2/String.html#method-i-split | ||
str = string.split(' ') | ||
This comment has been minimized.
Sorry, something went wrong.
jcdavison
|
||
return str.length | ||
end | ||
|
||
if __FILE__ == $0 | ||
|
1 comment
on commit 59959da
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, all solid work here 👍
Ruby 'implicitly' returns the last line of any method/function call, so you don't literally need
return
you could writecount
and you would be fine.