Ad
  • Custom User Avatar

    That's a good point. I chose reduce, because I preferred a declarative style for this exercise. Since the array contains only a few boxes, the performance difference is negligible. For a much larger dataset, though, I'd definitely switch to an early-exit loop. Thanks for the feedback!

  • Custom User Avatar

    The traverseBoxes uses a reduce method, that will iterate over all elements of the array, even if it finds the result on the first one. Consider:

    export function traverseBoxes(boxes: Box[], path: string[] = []): string[] {
    for (const box of boxes) {
    const result = pathToBomb(box, path);
    if (result.length > 0) return result;
    }
    return [];
    }

  • Custom User Avatar

    I agree: "Ghost objects are given a random color attribute"

    The color is an "attribute" of the object. So it should not change with each call to color.

  • Custom User Avatar

    Maybe the instructions have changed, but as they read now, I agree with vajdagabor. Currently the instructions say this:
    ghost = Ghost.new
    ghost.color #=> "white" or "yellow" or "purple" or "red"
    In my reading, that means that the ghost object will always return the same color. The color is not returned on instantiation, it's returned on a the .color method call of that particular instance of the Ghost class.

  • Custom User Avatar

    I agree with eik3 definition of the expected task. I also though it should assing color only upon initialization. Yet Denym is totally right. If so, then the kata creator should of defined this with a test.

  • Custom User Avatar

    Then the submit test cases should be different :)

  • Custom User Avatar

    That's how I read the description, it says "given random color when instantiated". I expect a valid solution to work this way:

    a = Ghost.new
    b = Ghost.new
    a.color #=> 'red'
    a.color #=> 'red'
    b.color #=> 'white'
    b.color #=> 'white'
    
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Nice and clean solution, however the pageItemCount method is not correct:

    p = new PaginationHelper([1,2,3,4,5,6,7,8], 4);
    p.pageItemCount(1) ;   // --> this returns 0 instead of 4
    
  • Custom User Avatar

    Good call. I've sent a new solution with this corrected regexp:

    /'?[a-z]+[a-z']*/i