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 I like about this solution is that if they kept expanding the pattern, it would literally be a matter of adding one to that array.
In that case (and this one too) I'd use a range, i.e.
(0..2)
which can be mapped, as it's enumerable.it was to do the " and " instead of ", " prior to the last segment of the formatted result
javascript array reduce can provide the index and the array (so you can know whether you are on the last one). this is a HACK to man-handle ruby. I didn't like it, but I am trying to learn how to do FP in ruby come hell or high water ;)
I guess I could have done the replace-the-last-comma-with-" and" HACK (but both are equally HACKs)
Why do you need the reverses?
maybe not!
is the ternary check on the last line necessary?
I would never have thought that xor would remove stuff from a Set
i tried to use first initially, but that didn't work so this is where I ended up, I like the solutions that use find.
nice and direct
This comment is hidden because it contains spoiler information about the solution
matter of taste, but ruby added the
#itself
method so you can do.group_by(&:itself)
there's an
#odd?
and#even?
method instead of having to do the division yourselfAlso, I don't know how you feel about buillding to the spec or being more guarded, but since the data is guaranteed to only have one matching value (with odd occurrances), you could use a
#find
instead of the#select
, meaning you would need one less call of#first
at the end.