Ad
  • Custom User Avatar

    The sample test cases clearly show the first behaviour instead of the latter :)

  • Custom User Avatar

    Thank you Moormaster for your solution and links provided on test framework, just realized as u mentioned prompt and alert could not work on this site for reasons of ui specially when we need to apply the test code, and the test should provide input data and result, your description on extracted functions are nice and complete.

    Need a little time to read and understand your code (as i'm a newbie) after that I will reply this post again as im trying to make this challenge complete for submission on kata which now thanks to data you provided should be possible...

  • Custom User Avatar

    To write tests for your code you first need to refactor it into smaller test-able units. The existing function in your code contains user-interaction (alert(), prompt(), ...) which makes it impossible to test using a unit-test framework like codewars provides.

    I have done some refactoring and uploaded them as fork -> https://www.codewars.com/kumite/604243f85a72ae000d16e0bf?sel=60434735db87fd000c194e99

    I extracted functions for

    • determining which element wins when two elements (i.e. Rock and Scissors) are passed as parameters
    • determining which player wins (first or second parameter) when two elements are passed as parameters
    • determining a descriptive message for each round that
      • contains the correct verb for the winning element (i.e. crushes when Rock has won)
      • starts with a word describing who has won ("Your ...", "CPU ...")

    ... and also started to write some tests for the first function.

    I decided not to use the internal test framework from codewars but chose to use "Mocha BDD" instead (you can simply select it in your Kumite/Kata when designing a new one). I think it is more useful to learn how to use real-world test-frameworks when starting to learn about unit-tests. Mocha is often used in combination with an assertion framework - I have used "chai" in my case. You can find information about how both frameworks work and what they do here:

    https://mochajs.org/#getting-started
    https://mochajs.org/#interfaces
    https://www.chaijs.com/guide/styles/#assert

    Maybe it helps you as a starting point on how to write tests for your code ... and also on how to create Kumites/Katas for Codewars :)

  • Custom User Avatar

    Thank you, ye i tried to do it from sctrach and it works fine on my developer but somehow cant figure out the test code that i need to write so that it works on this codewars website too

  • Custom User Avatar

    I don't know anything about JavaScript but if you think that's a long script then you should see some of my batch scripts. Pure italian spaghetti code.

    Nonetheless good job and its nice that you challenged yourself!

  • Custom User Avatar

    kata suggestion != kata solution (回馈不等于答案~~)

  • Custom User Avatar

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

  • Custom User Avatar

    Description of this Kata is somewhat vague, the 2 example output presented with the Kata are:
    arrayDiff([1,2],[1]) == [2]
    arrayDiff([1,2,2,2,3],[2]) == [1,3]

    There is another possibility in which 1st array has multiple occurrences but the second array does not include that specific value, in which we dont know if the final result should also singleout those multiple occurrences or include all those multiple occurrences:

    arrayDiff([1,2,2,2,3],[1]) == [2,2,2,3]

    or

    arrayDiff([1,2,2,2,3],[1]) == [2,3]