Ad
  • 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

    Thank you for the reply. :)
    Will revise my code

  • Custom User Avatar

    You're not supposed to give a reader argument to DocumentParser.prototype.parse. You're supposed to call the getChunk() method from the reader instance that is already provided to the constructor of the DocumentParser object.
    So you can perform these changes :

    // replace this
    DocumentParser.prototype.parse = function (reader) {
    // by this :
    DocumentParser.prototype.parse = function () {
    // and, each time you want to call the 'getChunk()' method, use this : 
    this.reader.getChunk()
    

    And then you can implement and test your solution.

    (I let the issue open since it's a strange behavior and most likely truly a bug...)

  • Custom User Avatar

    Is this a bug or did I just misunderstood something?
    I tried to console.log the output within parse() and it seems like I get correct char, word, and line counts (on the initial test case: "Once upon a time")

    This error shows upon Test (not on submit)

    TypeError: Cannot read properties of undefined (reading 'getChunk')
        at DocumentParser.parse (test.js:54:21)
        at Context.<anonymous> (test.js:93:12)
        at process.processImmediate (node:internal/timers:471:21)
    

    Appreciate any feedback :)