Skip to content

Conversation

@matthewlee07
Copy link

Thanks for the review!

"F"
else
"Invalid Input"
end
Copy link

@sjreich sjreich Sep 28, 2018

Choose a reason for hiding this comment

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

Nice, clean solution.

Tackling the invalid inputs is an extra step, but let's talk about the best way to do that. This might be a good case for using a guard clause up front - something like return 'Invalid Input' unless integer.is_a? Integer. But that gets me thinking about what the desired behavior would actually be here. Obviously, this all depends on what sort of broader program this method would appear in, but my hunch is that in most use cases, either returning nil or raising a TypeError would be more helpful than returning a different string.

letsdrill.rb Outdated

#Put your code here!

array.sort_by {|string| string.length}[0]
Copy link

Choose a reason for hiding this comment

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

Nice. Ruby has first, so that is typically preferred to [0] for stylistic reasons. But also, scan through the ruby Enumerable documentation, and see if you can't find a method that is even more fitting than what you have here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants