Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here's my solution! #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions letsdrill.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
def get_letter_grade(integer)

#Put your code here!
### Using some ternaries (ternarys? ternararies?)

integer >= 90 ? "A" :
integer >= 80 ? "B" :
integer >= 70 ? "C" :
integer >= 60 ? "D" :
"F"

end

def shortest_string(array)

#Put your code here!

# First guess that the first array
# element is the shortest.
shortest = array[0]

# Iterate through each string in the array
array.each {|string|
# If the string we're looking at is shorter than
# the shortest we've seen so far...
if string.length < shortest.length
# ...set the shortest string to this
# current string.
shortest = string
end
}
# Implicit return! Because we can!
shortest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very easy to read. 👍

Ruby provides many methods to built-in classes. In particular, all these methods on Enumerable are available to instances of Array.

Consider rewriting this method to sort the input array by the length of the elements, then just plucking off the answer.

Or, if you scan through those Enumerable methods, you might find min_by which basically does the whole thing for you. But what's the fun in that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the feedback!

end


Expand Down