Ad
  • Default User Avatar

    It was an issue 7 years ago, other people reported similar problems - server-side tests (I guess node.js) were handling the copying/cloning not the same way chrome was doing it.

    The tests may be working fine, but they work (at least worked) differently in different interpretators.

    It's not issue with my code. I've reported that my code produces different outputs when it's run in browser and on your server.

    Closing it like this 7 years later is just rude.

    Good thing I'm not investing my time into this website anymore.

  • Custom User Avatar

    Issue with your code is not an issue, JS's tests work fine

  • Custom User Avatar

    In JS you copy the outer array then each element (inner array):

    map = map.map(row=>row.slice());
    //Array.prototype.slice copies an entire array
    //Array.prototype.map returns a new array as well so no need to slice the outer array
    
  • Custom User Avatar

    Same problem, I used thingy called "deep copy". It copies from another copy or something like that. In Ruby the syntax is name1 = Marshal.load(Marshal.dump(name2)). Pretty sure there is something like that in JavaScript.

  • Default User Avatar

    I have the same problem,how to solve it?

  • Default User Avatar

    Well, there is the test that I mentioned in my original comment. The result I'm getting in my chrome is different from the result codewars shows on 'Run Tests' command.

    Would you care to check a demo I set up at external website?

  • Default User Avatar

    I think good ol' console.log() can help; you with it.
    And making test increasingly difficult, i.e. start with a trivial case then add "more complex test" until you get to the point you want

  • Default User Avatar

    I've created simple solution using recursion in JavaScript.

    This particular test case: 'A pretty simple map (2x2) - Should return the only moves necessary' produces different results when my solution is executed in browser (manually by me) and when it's run server-side ('Run Tests') mode.

    I've read comments here and rewrote solution so it doesn't update the map (though it was working locally even with map being changed while solving).

    However, it still produces different results.

    My guess is that server side Javascript interpreter here is dealing with recursion in a different way.

    Question: how to debug a problem like this?