Ad
  • Custom User Avatar

    "==" is valid if you're comparing two primitive types of data, like Integers, booleans and so. Otherwise, you use .equals(), that is a default method from every object to compare objects (In this case, any instance of 'String' is an object so you must use .equals() to compare two Strings).

  • Custom User Avatar

    could use ternary operator to make this shorter

  • Custom User Avatar

    ik its been 7 months but I'll answer for anyone new here. .equals() is used to compare two Strings. == is for numbers.

  • Custom User Avatar

    Hi,

    • The description isn't very clear, or rather, it's confusing about what has to be swppped or not. Especially, the fact that only the 2 first occurencies must be swapped, and not every two pairs should imo be clarified.

    The random tests are currently totally wrong...

    • 10000 tests are totally useless. 100 are enough. Or if you want to test for efficiency, you need much longer arrays.
    • assertEquals is deprecated for arrays. Use assertArrayEquals instead
    • the random intput are not random at all, but always the same: [00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
    • ...and this is the only reason nobody noticed the general setup is wrong: the same array object is sent to the user and to the reference solution, where you mutate it in place, meaning that the user is receiving your output as input and will regenerate the original input. And if he works properly, copying the input array, he'll get failed assertions with a correct code beacuse the ref solution is using (very) bad habits. => create a copy of the input and don't modify the original array.

    cheers

  • Custom User Avatar

    Well, he did upvote it anyway: both the kata and solution itself. Even if your version was true, there are other ways to share code, and I'm really not sure how he could help you debug, when he can't create or edit a kata himself yet... Anyway, just a friendly warning.

  • Custom User Avatar

    It wasn't so he could upvote it, it was so he could help me debug.

  • Custom User Avatar

    Do you want to explain how you 2 got the exact same solution? Giving away solution so a buddy can upvote your kata is unaccaptable here.

  • Custom User Avatar

    Tests throw warnings.

  • Custom User Avatar

    Fixed, and I changed the example to accomodate for that, thanks!

  • Custom User Avatar

    If two variables "match"

    I'd describe that as "elements", not "variables".

    Consider describing an example with more elements that start with 'a'. This does not really make clear that it's the 'a' that inhibits further swaps; the reason here might still be that the later element had already been swapped.

  • Default User Avatar

    Thanks! Now I won't have to learn those nasty bitwise operations! LOL!