5 kyu

Randomize Objects

320 of 322surtich
Description
Loading description...
Algorithms
Fundamentals
Arrays
  • Please sign in or sign up to leave a comment.
  • stanislavrepin Avatar

    Hi. I got this error - "calling toRandomArray() and then try to get a given permutation of values After 100 attempts, has not obtained the desired permutation. Check the randomness of your solution." All tests pass except for this one. Could you tell me what is the test case fail?

  • RealKenshiro Avatar

    The value types that need to be considered are string and number. That should be stated in the description.

  • Welblaud Avatar

    As for the code, everything goes well if I am testing it outside of the kata. No problems with many nested levels, no problems with empty objects. However, I pass 6 tests from (?? 312 ??). I have no idea whether it is really expected I will write the tests. Is it? I haven’t checked other peoples’ solutions but I guess recursion is needed here, isn’t it? If so, the level of this kata is rather low!

  • frantic1048 Avatar

    I tested my code on node v0.10.35, and on my Firefox 36. No errors ocurred.

    But this kata can't be solved.I'm new to Codewars.I can only see the Output just shows Incorrect!

    I wonder if there's any error ocurred.Or I've misunderstood the kata's description ?

    What I've implemented:

    • obj = {}
      • obj.random(): return undefined.
      • obj.toRandomArray(): return [].
    • obj have many keys and values
      • obj.random(): return a random selected value from all non-Object value.
      • obj.toRandomArray(): return a random ordered Array consists of all non-Object value.
  • m2web Avatar

    Are the test cases for this kata available for viewing? Being new to the site I just do not know where to look. Thanks!

    • surtich Avatar

      No, the tests cases are not available for viewing. You have to solve the kata from the instructions. By sending the code, you'll see what you're failing.

    • m2web Avatar

      I setup and tested the solution with Jasmine and the tests are passing. However, not when I sumbit the solution on the site.

    • surtich Avatar

      Probably your solution has an error. When you submit the solution, what error message you see on the screen?

  • yangchen Avatar

    The "calling toRandomArray() and then try to get each value of the random array calling 100 times as much " case should add "checked = false" above the "while..."

  • Nibbs- Avatar

    This comment has been hidden.

    • surtich Avatar

      This comment has been hidden.

    • m2web Avatar

      Here is the output: Empty object tests Test Passed: Value == undefined Test Passed: Value == [] Object with one key tests obj.random() should return the only key - Expected: 1, instead got: undefined Test Passed: Value == [1] Object with one key multiple levels tests obj.random() should return the only key - Expected: 1, instead got: undefined Test Passed: Value == [1]

    • surtich Avatar

      This comment has been hidden.

  • laurent.malvert Avatar

    5 kyu seems a bit high for that one. 6 kyu maybe?

  • osuushi Avatar

    You talk about returning "keys", but it looks like you actually want values.

  • OverZealous Avatar

    This needs better test cases.

    There's no messages on the tests, and the tests are using Test.expect(value, msg), which doesn't tell you anything about the values being tested. Instead, you should use one of the assert methods, like Test.assertEquals(actual, expected, msg), and make sure you include a message as to what was tested.

    I also recommend grouping your tests into describe() and it() blocks for better feedback.

    As it stands, this isn't very solveable harder to solve than necessary, since I'm getting no feedback on the failures.

    • surtich Avatar

      Thanks for your suggestions.

      I have refactored the tests grouping with describe() and it().

      However, most of the tests still using Test.expect(value, msg). The reason is that what I do is to check that the methods actually generate random values and neither would be informative to use Test.assertEquals(actual, expected, msg). What I have done is add descriptive messages about what is wrong.

      I hope this helps!

    • OverZealous Avatar

      The grouping helps a bunch, and the tests are much, much better. Thanks!

      You could still use assertEquals in some places. For example, in "toRandomArray() tests", you could use it to assert the length (helpful because the user can see what the length of their array actually was without using console.log().

      You also should add in which value was missing from the array into your message. That might be helpful.

      Another option (which might not be better, so feel free to disregard this) would be to use Test.assertSimilar(actualArray.sort(), expectedArray.sort(), "Sorted arrays were not equal").

    • surtich Avatar

      Thanks, again. You've helped me a lot!

      I followed your first two advices. I think that is more informative than using Test.assertSimilar(actualArray.sort(), expectedArray.sort(), "Sorted arrays were not equal").