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.
I think you can either drop the filter part or change regexp to
/(, )(\S+)$/
(or even/, (\S+)$/, 'and $1'
) to avoid redundancy.Well done on remembering / finding the 'filter' keyword... woulda saved me a world of pain.
Great, super well done wish I had done so well. I would only say personally I would change a paramater to word
i isn't declared in the function - so I would be wary to consider this best practices. Could definitely create some unwanted side effects.
That's exactly my point. I see a lot of solutions that use 'this.value' and 'this.next' in their constructor. This causes every instance of ListNode to expose both those values, allowing anyone to edit them. I think this Kata should have some sort of check to make sure that each node is in fact immutable.
Mutating values in the list is not really in keeping with the functional spirit of the kata.
What exactly does immutable mean? If I implement ListNode as detailed in the initial code (ListNode.prototype.someFunc = function() {}), it means I need to store the value and next args in properties of the ListNode instance so that my prototype functions can access them. This would allow me to do this:
My question boils down to this: Does immutable apply to the list's structure only, or does it also apply to each node's value?
I think the exercise was pretty interesting. The only change I would make is to "White space should not be left in the result string as is." I would remove that "not" in the middle, so it reads "White space should be left in the result string as is." Otherwise, it leads one to understand that we should trim white space, so as to keep a normal flow of text (i.e. all lines start with a non-white space character, so it all looks aligned).
I agree with ineiti and myf. My solution kept failing because I was removing trailing and preceding whitespace from my lines. "White space should not be left in the result string as is" is misleading.