Ad
  • Custom User Avatar

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

  • Custom User Avatar

    @hobovsky You make a good point, and I don't disagree, but I think the bigger issue is that katas, much like Science experiments, should have as much of a controlled environment as possible to ensure the user can focus on the variable of solving the problem and not figuring out an error unrelated to the problem. Not that this isn't a good lesson for the user to learn, it's just not the focus of the kata and should be avoided. If part of the training was ensuring the user wasn't using for...in for this reason then yes, this would absolutely be user error.
    Also, the kata should be held to a higher standard than the user's code, so the Array.prototype.shuffle addition is an error with the kata (IMO).

  • Custom User Avatar

    You are correct, as stated in the Stackoverflow link. for..in should be avoided for this reason as should adding properties to built-in Object prototypes.

  • Custom User Avatar

    [javascript] 'shuffle' exposed as index on arrays.

    For users having this issue:
    The quick fix for this in your code is to change your for..in loops to this:

    // old code:
    for (let i in voters) {
      // throwing error of voters[i] being undefined because i === 'shuffle'
    }
    // new code:
    for (let [i] of voters.entries()) {
      // Unchanged code
    }
    

    For Kata Author:
    In test cases, this is getting added to the Array object's prototype:
    Array.prototype.shuffle=function(){...}
    As a result, 'shuffle' gets added as an "index" in for..in loops.
    Example:

    let arr = ['a', 'b'];
    for (let i in arr) { console.log(i); }
    // console:
    // 0
    // 1
    Array.prototype.shuffle = () => {};
    for (let i in arr) { console.log(i); }
    // console:
    // 0
    // 1
    // shuffle
    

    This will inadvertently cause an error in a user's solution who are using a for..in loop in their solution.

    for (let i in voters) {
      let topVote = voters[i][0]; // throws an error because voters['shuffle'] is undefined
    }
    

    In general, it's best to avoid modifying the prototype of built-in objects. Instead just create a standalone shuffle helper function, or if you absolutely need to add it to the Array prototype, use the Object.defineProperty method:

    Object.defineProperty(Array.prototype, 'shuffle', {
      value: () => { /* add code here */ }
    });
    

    Relevant Stackoverflow: https://stackoverflow.com/a/948379/354317

  • Custom User Avatar

    Also, in the instructions here:

    This reader exposes only one method : getChunk()

    Returns the following fragment of text from the file it is reading
    Returns a string of random size
    Returns at least one char
    Returns an empty string when finished

    I would just get rid of "Returns at least one char" Maybe just have this:

    This reader exposes only one method : getChunk()
    Returns a fragment of text from the file it is reading as a string.
    The fragment can be any length, including 0 (empty string).
    If the fragment is an empty string, the reader has reached the end of the file, and will only return an empty string on subsequent calls.

    I think I understand why it says it will return at least one char, but I think it means to say, "if doesn't return an empty string, the string will be a minimum of 1 char" which is kind of redundant info and confusing.

  • Custom User Avatar

    but what about this test case:

    testX:
    {
      text: "A\n\nB",
      words: 2,
      chars: 2,
      lines: 2 // or 3?  If 3, then an "empty line" is a line, and thus test4 in your example should have 1 line.
    }
    
  • Custom User Avatar

    From the instructions:

    This reader expose only one method : getChunk()
    
    Returns the following fragment of text from the file it is reading
    Returns a string of random size
    Returns at least one char
    Returns an empty string when finished
    

    In the instructions, it states that the getChunk function exposed by the reader "Returns at least one char".
    One of the test cases, the first chunk received by the parse method is an empty string (so the entire string it was reading must be an empty string), thus making the charCount, wordCount, and lineCount expected to be 0.
    Even if it was allowed that the first string received by getChunk was an empty string, there are other tests where there are empty lines that count as a line, so wouldn't an empty string test case still have a lineCount of 1?

    Example:

    chunk = 'foo\n\nbar'
    expected result:
    charCount: 6
    wordCount: 2
    lineCount: 3
    

    and if that's the case, then shouldn't this be true:

    chunk = ''
    charCount: 0
    wordCount: 0
    lineCount: 1
    
  • Custom User Avatar

    I've not written a Kata before, but I'd see if you could import the user's code as a module instead of adding the solution.txt file inline to the index.js file. Then a user couldn't circumvent the testing like this.

  • Custom User Avatar

    Is there a way to undo the solution/points? I feel dirty.

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    @xDranik, makes sense now. I confused sets with intervals. Regardless of the type of interval (closed, half-closed, etc...) the interval would still be the same. Sorry if I confused anyone further on this.

    @OverZealous, thanks for the visuals.

  • Custom User Avatar

    Thanks for the clarification. So in determining if the value of x is within the interval [1, 5], I could express that mathematically as 1 <= x < 5.

    I feel like the instructions could be more clear on this rather than having to extrapolate whether the first and/or last number are included in the interval.

    "[1, 5] is an interval from 1 to 4. The length of this interval is 4." This would be better because if someone asks you to count "from 1 to 5", you would undoubtedly count: 1, 2, 3, 4, 5.

    Edit:

    This kind of interval is referred to as a "half-closed interval". In interval notation, it would be written as [a, b). Which I think would make for a slightly more compelling Kata. Instead of having an array of arrays, have an array of interval notations in the form of strings.

    ["[1,4)", "[7,10)", "[3,5)"]  // Length is 8
    ["(1,4)", "(7,10)", "[3,5]"]  // Length is 6
    

    Anyways, fun Kata. Could be slightly more clear. Would be interested to see a remake of this Kata using interval notation rather than a 2d array.

  • Custom User Avatar

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

  • Custom User Avatar

    I did read the description/instructions in their entirety before voting and I'm saying I don't understand from the description how to achieve the intended solution. I understand that I'm supposed to create a 2D array based on the townSize parameter passed in. I then understand that I'm supposed to snake (traverse) through the 2D array depositing an incremented value that shows the path taken through the 2D array. I understand that a -1 means to go left/up, 0 means to go left or right/up or down, and 1 means to go right/down (street/avenue).

    I don't understand where I'm supposed to start in the 2D array or if it's assumed that I have to start at index [0, 0]. I don't understand how the values in the streets and avenues parameters relate to my current position in the town. For example, given your example compute(3, streets, avenues), how do I know to start at index [0, 0] (where I would deposit a value of 1) and move right? From your instructions, a 1 would allow me to move right and a 0 would allow me to move left or right.

    I'm not trying to be mean, I'm trying to be helpful and understand your kata. The first step would be to learn how to edit the kata. The next step would be to ensure that the return value of the compute function will pass your Test expectations. Your first test expects [[1,2,3],[6,5,4],[7,8,9]] as a return value. If I write this inside the compute function: return [[1,2,3],[6,5,4],[7,8,9]];, the kata still fails. I tried wrapping it in a string and also tried stringifying it with JSON, which neither worked. So I believe you have issues with your Test fixture comparing array values. I pointed this out in my previous comment and how to solve that because as it stands, this is what happens: Test Failed: Expected: [[1,2,3],[6,5,4],[7,8,9]], instead got: [[1,2,3],[6,5,4],[7,8,9]]

    So it's an interesting concept for a kata but I don't think it's ready.

  • Loading more items...