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's why I threw a quick "ary = words.chars and" in front of my words.select
"Hashes enumerate their values in the order that the corresponding keys were inserted."
... I love this language
Ah that makes sense. Thank you both.
Yep! It does little more than allow us to define new
instance
s which differ from the inner type.Precisely.
x and y are of type
[a]
, notLengthList a
.Consider these two ways of writing a function:
and
In the first example, the argument is simply bound to the identifier "x"; hence, x has type
LengthList a
. In the second example, however, we pattern-match on the argument, and bind the contents of the LengthList to the indentifier "x". So in the second example x has type[a]
.Hope that helps.
What allows you to call length on x and y, if they are of type LengthList? Why do they still respond to list functions?
Maybe the greater question is - is newtype LengthList simple a wrapper?
Also... is
instance Ord a
... defining how LengthList will respond to the functions defined by the Ord typeclass?This solution is similar to mine (but I used looping)
No need for square brackets.
Like the use of partition, but you are comparing the whole word instead of just the first letter like the specification states.
Nice one-liner, but you are wasting a lot of cycles repeatedly calling "word.chars.sort". I would recommend assigning that to a variable right off and then use that variable in your select.
reduce
will throw an error, I suppose. A more correct answer would change the end to:What happens if "number" is 0, 1, or 2?
Very clean, I like the recursion, but you can't rely on a hash to maintain its ordering. I would recommend getting the keys, sorting them, then using each, or have a second with the roman numerals to use each on, since you can rely on the ordering of an array.