Ad
  • Default User Avatar

    I think you can either drop the filter part or change regexp to /(, )(\S+)$/ (or even /, (\S+)$/, 'and $1') to avoid redundancy.

  • Custom User Avatar

    Well done on remembering / finding the 'filter' keyword... woulda saved me a world of pain.

  • Custom User Avatar

    Great, super well done wish I had done so well. I would only say personally I would change a paramater to word

  • Custom User Avatar

    i isn't declared in the function - so I would be wary to consider this best practices. Could definitely create some unwanted side effects.

  • Custom User Avatar

    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.

  • Default User Avatar

    Mutating values in the list is not really in keeping with the functional spirit of the kata.

  • Custom User Avatar

    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:

    // Let's assume that my constructor for ListNode sets this.v and this.n
    var l = new ListNode(3, new EmptyList()).push(2).push(1);
    l.toString(); // (1 2 3);
    l.v = 9;
    l.toString(); // (9 2 3);
    

    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?

  • Custom User Avatar

    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).

  • Custom User Avatar

    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.