Ad
  • Custom User Avatar

    missing invalid tests:

    Test.assertEquals(convertRomanToDecimal("IXLXXX"), -1);
    Test.assertEquals(convertRomanToDecimal("CMXLIIII"), -1);
    Test.assertEquals(convertRomanToDecimal("CMIIIXL"), -1);
    
  • Custom User Avatar

    no random tests

    @Johan: what the HELL are you doing!??

  • Custom User Avatar

    This is a trivial duplicate.

  • Custom User Avatar

    Great kata! And solid explanation, too; I've had so much trouble trying to figure out the ins and outs of this format while trying other katas. I even used this explanation to solve the linked validation kata!

  • Custom User Avatar
  • Custom User Avatar

    Yes, if you click on View Solution you're not getting everything. I guess it's a bug, or maybe a feature, of CodeWars. You can look up the full source on the solutions page.

    [...s] is shorthand for s.split("") (where s is a string) using the spread operator. I can't find a decent MDN reference for this, but [..."abc"] === ["a","b","c"].

  • Custom User Avatar

    Thanks to all of you for these useful comments!! OMG!! I would never have found out by myself!!
    JohanWiltink, I am not able to see the last line of your solution. I think it's incomplete.
    I try to understand this last line. Is [...s] another type of sort code trick?
    Thanks again :D

  • Custom User Avatar

    And functions of zero arguments are possible in both syntax variations. (In this case, you cannot leave out the parentheses with the fat arrow syntax. You'd have nothing left. :)

    function pi() { return 3.14; }
    const pi = () => 3.14 ;
    

    You could then use pi() for 3.14. It's sort of a constant, if it doesn't reference outside state (which my solution does! so it's not a constant anymore).

  • Custom User Avatar

    See MDN

    "function" functions can also be anonymous; that's not the difference. It's just a different, shorter syntax with some restrictions and limitations.

    The following examples are all more or less equivalent

    // function declaration
    function identity(arg) {
      return arg;
    }
    // assignment of (anonymous) function expression
    const identity = function(arg) {
      return arg;
    };
    // assignment of function expression
    const identity = (arg) => {
      return arg;
    };
    // if there is exactly one argument, you don't have to enclose it in parentheses
    const identity = arg => {
      return arg;
    };
    // you can replace the function body by an expression, which will then be returned (evaluated)
    const identity = arg =>
      arg
    ;
    // this can go on one line (all of the above could, also). but I usually break after the fat arrow
    const identity = arg => arg ;
    
  • Custom User Avatar

    It is an anonymous function. An example will help

    function name(v) {
      return v;
    }
    //same as
    name = v => v;
    

    The only thing that is different is the context of this inside an arrow function otherwise it's just like an ordinary function :) hope that helps...

  • Custom User Avatar

    Ok, I see your point now, thanks.
    But, I have troubles to understand your code. I am newbie with javascript.
    Please, Could you tell me what is the functionality of => operator? I searched in W3School web and google, but, I couldn't find it.
    Where is v variable coming from?
    If you can share any reference or web page, I would look up it by myself.
    I want to undersand your code, because I think I would learn, Many thanks! :D

  • Custom User Avatar
  • Custom User Avatar

    Yes, my solution is very cool :]

  • Custom User Avatar

    Random tests guard against someone just enumerating correct answers, instead of really solving the kata.

    Did you see my second solution? No Roman numeral in sight there, yet it passes. This is impossible with random tests.

    In short, it prevents cheating.

  • Custom User Avatar

    Hi! Thanks for the review.
    I added a test for empty string.
    I don't get why I need to add a radom tests?
    I included some non-well and well formatted roman numerals inside of test cases. Test cases should be as simple as possible, so these are easy to verify and correct. I don't see the advance of aleatory number a part of If I test all the possible cases.
    Could you please be more specific? I am still learning TDD.
    Thanks!

  • Loading more items...