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.
That is an extra fail-safe. In the chance that
strarr.each_cons(k).map(&:join).max_by(&:length)
returnsnil
, which it will if the arraystrarr
is empty, then an empty string will be returned. Sincenil
is falsey,''
(the empty string) will be returned when the||
expression is evaluated on the last line—since strings are considered truthy. The first line of the method should handle cases wherestrarr
points to an empty string, but it's not bad to have a back up.what is the purpose of || "" at the end?
Wow this is amazing
each_cons is so good. but i don't want to using it.
It allows you to pass a method in as a symbol instead of passing in a block to the method itself, which makes it automatically reflexive without any further work. Below would be the longer version of the above example for that part.
nice catch
i dont truly understand how the & works
New methods I did not know about! .each_cons, max_by, great stuff!
The idea is amazing, I love it very much. but the code itself is a little weak. For example :("-3 - 1 * 2 + 2 - 7") have different result with ("-3 -1 * 2 + 2 - 7"). one purpose, two result.
I like your idea!
the each_cons changed my life