Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Interesting solution!
For anyone wondering how this works...
Gsub is producing a template string with
'%s'
, this is later replaced by the value ofs.delete(' ').chars.reverse
, which is the string in reverse without spaces.How?
Well, the
%
symbol between the two expressions is actually a formatting method, from theString
class.It recognizes the
'%s'
& replaces it with the value.This means that
s.gsub(/\w/, '%s')
will produce strings like this:Then this template is replaced into the final solution.
Hope this helps! :)
This comment is hidden because it contains spoiler information about the solution
What happens if I call your method with a Range instead of an Array?
Ranges implement
each
, but notjoin
.This comment is hidden because it contains spoiler information about the solution
Hi, great job here with the string formatting, clever use of the
clamp
method, and the case statement.Just two things I'd like to point out, if you're open to suggestions.
Let me know what you think :)
I like what you did with the string formatting at the end.
But I think you can improve this.
Here's how:
We usually put value constants as all capital letters so we can tell them apart from class names, which are also constants.
Also it helps to give it a name that means something, not an abreviation.
Because these sections represent math operations, I would name this constant
OPERATIONS
, or if you would like to follow the problem domain vocabulary you could useINSTRUCTIONS
.As a result, you get code that's easier to read & make sense of.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yes, the spaceship operator is used for comparing two Ruby objects.
It can return 3 possible values:
Where -1 means that the object on the right side of the operation is smaller than the other object.
Then 0 means that the objects are equal.
And 1 means the object on the right i greater then the other object.
I don't think you need to scan for A-Z since you're downcasing the string :)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
You don't need the return here :)
Loading more items...