JavaScript version works?

  • 0


    It looks like the JavaScript version of the test is flawed, but I may be mistaken.

    1. Comments at the end of the example: var obj = Object.create(RandomizedCollection).createNew(). Looks like this isn't the case, as running the code with a testcase shows a constructor is needed, so it's a new RandomizedCollection(); that's performed
    2. Running the code expects specific items returned by getRandom(): not sure if that's normal, I hope it isn't the case when submitting the code
    3. Submitting my code resulted in a Runtime Error even though running it with the same test case worked
    4. Test case values used when submitting the code looked wrong as there were a few inserts then many identical calls to getRandom(), not sure if that's normal

    So I wrote some code to work the example provided obj = Object.create(RandomizedCollection).createNew(), which didn't run. Then I wrote it to work with a call to new RandomizedCollection() and that one passed (except for the getRandom() call, which was randomly right.

    I'm not yet used to this website so I hope I'm not missing something obvious.


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.