Ad
  • Custom User Avatar

    Rejected because of missing random tests. If you want to improve this you can fork this translation. Also please upghrade to JUnit 5 then.

  • Custom User Avatar

    i think var will make counter accessible via constructor, and there was no test for this case

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    Duplicate, differences: - midnight; + hyphens between twenty [ord]; + redundant am/pm in input

  • Custom User Avatar

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

  • Default User Avatar

    How does the instances have access to the counter variable? It's not passed as a method (e.g this.counter), it's not passed as a prototype either (e.g Counter.prototype.counter).

    So how? Closure? That would make sense if we call it directly on the Counter function constructor, not its instances.

  • Custom User Avatar

    Recursion is beauty here!

  • Custom User Avatar

    The problem was with my code indeed! I simplified the solution and it passed normally on Codewars now.

    I have my local repo setup with TS, mocha and ts-node and I execute the test task in package.json to verify that all tests pass.

      ...
      "test": "mocha \"test/**/*.{ts,js}\" --recursive -r \"ts-node/register\" -r \"tsconfig-paths/register\"",
      ...
    

    It's with this setup that my erroneous code passed and I want to investigate further why that was the case.
    When I executed via a classic node cli terminal locally, it threw the same memory error as Codewars did!

    I will post here my findings when I find out what magic did the TS compiler and my code passed in the first iteration.

  • Custom User Avatar

    You might be running into an infinite loop or something... The error says you tried to allocate too much memory, possibly for a very big array. I'd bet that's from your code, and not the tests. Did you try logging stuff to console to see if that's the case?

  • Custom User Avatar

    In such case, it's difficult to tell why it does not work without seeing it. Kata seems to be OK.

  • Custom User Avatar

    It throws this error even with the sample tests which use simple and small arrays. The same sample tests and even more complicated ones with object references pass with flying colors locally. This memory error is very strange. That's why I posed the question tentatively and not marked as an issue.

  • Custom User Avatar

    Just solved the kata in JS and encountered no problems.

    Did you try to run similar test case, with similar sizes of arrays, locally in your IDE? There's a big chance that it will fail for you also locally (this FAQ could be helpful).

  • Custom User Avatar

    I've authored a JS solution that works on my machine (at least for various cases that I created and the sample tests provided), however when trying on CodeWars I get this stacktrace:

    <--- Last few GCs --->
    
    [1:0x563c8a521000]     3487 ms: Mark-sweep 580.5 (592.2) -> 580.5 (592.2) MB, 198.8 / 0.0 ms  allocation failure GC in old space requested
    [1:0x563c8a521000]     3686 ms: Mark-sweep 580.5 (592.2) -> 580.4 (585.2) MB, 199.4 / 0.0 ms  last resort GC in old space requested
    [1:0x563c8a521000]     3888 ms: Mark-sweep 580.4 (585.2) -> 580.4 (585.2) MB, 201.4 / 0.0 ms  last resort GC in old space requested
    
    
    <--- JS stacktrace --->
    
    ==== JS stack trace =========================================
    
    Security context: 0x2ef7f64a57c1 <JSObject>
        1: combine [/home/codewarrior/index.js:~5] [pc=0x371d80b0c4e2](this=0x15be678c211 <JSGlobal Object>)
        2: arguments adaptor frame: 4->0
        3: /* anonymous */ [/home/codewarrior/index.js:36] [bytecode=0x3b47ab84d949 offset=222](this=0x15be678c211 <JSGlobal Object>)
        4: /* anonymous */ [/runner/frameworks/javascript/cw-2.js:152] [bytecode=0x3b47ab846851 offset=145](this=0x15be678c211 <JS...
     
     STDERR
    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
    

    Can someone please tell me if this error originates from my code or it's a CodeWars platform error?
    The general error at the end reads "JavaScript heap out of memory" yet I am not using memory intensively, working with indices mostly, nor am I modifying input arrays.

  • Custom User Avatar

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

  • Loading more items...