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.
What's the difference with
.detect
?For some reason, doing this did not work when I attempted it... and only worked once I removed the ampersand.
I'm still not certain how closures work in Ruby... hell, I'm not even certain that is the concept I should be looking up.
How is using reduce writing your own reduce ?
A little nitpicky, but you only need to run &block on each element once, not twice: find list.select(&block) as var, and then return as the second element all elements in list and not in var. If &block is expensive, it might be desirable not to run it twice.
Actually, the "Enumerable Magic" katas are explicitly for beginner exploration.
See previous discussions:
WHile this obviously works, I think the point of the excercise was to rebuild this built-in method yourself
I believe that without self it would not know what iterable object it was iterating over.
So without specifying 'self' it just forwards it to the existing upcase method?
Gives the result wanted? It's solved.
You people should really look at the kyu of this kata. It is meant to introduce enumerables to beginners. There are higher kyu katas that explicitly disable native methods to teach other concepts. This is not one of them.
In any case wrapping it in this way would be consider a horrible indirection and a bad practice. Would be better to just use
Enumerable.max_by
directly. It also breaks the ruby spirit of having all messages related to a class as methods of the same class.Yeaaah! Nice, man. :)
Thank You :)
It's as simple as it looks like while I read about ruby build-in max_by.
Hey @gregziolo, sup? The documentation for the
max_by
method: http://ruby-doc.org/core-2.2.2/Enumerable.html#method-i-max_byThey get the max value from an Enumerable, in this case a list.
The
&block
is the block you pass as a parameter for themax_by
. e.gAny doubt, please reply! :D
how does it works?
Loading more items...