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.
You should avoid at all cost switch/case statements, its a case smell.
This solution and others like it has helped me a lot with refactoring
Thanks for the tip. I think the Kata description has changed since I wrote my solution.
Nice regex, but the type checking is wrong. The statement says "If n is not an integer, return an empty value."
Try using #instance_of? or #is_a? instead of a "truthy" test.
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.Thank you for this comment rsrs. I started to study this year and I was looking and wondering why people were converting to strings and than back to integer
what if the sequence 'step' isn't one? what if it's increasing by 2 for example?
Matches any substrings of consecutive non space characters. See here for example.
Could you explain to me what the "\ S +" does?
If the resulting array is empty, calling
first
will yieldnil
, which needs to be converted into0
. This can be done either by usingto_i
or|| 0
.Why would .to_i be necessary? The array consists of integers only.
Well done.
what is the purpose of || "" at the end?
Each time its 5 times less code than mine :D
Okay Gauss
Loading more items...