Ad
  • Default User Avatar

    Having some spaces would be nice for sure. (But if there's a variant with spaces, it's grouped with this solution.)

    I mean this is not so readable and understandable as compare to basic if else, but it will be efficient i guess.

    It's rather the opposite: equally or even more readable, but not better in terms of performance.

    What is the benefit?

    Not repeating the same thing. It always returning a value and the value is always derived from another value.

    When working with other people on a large code base, clever one liners are not the answer.

    True. But I wouldn't call it a clever (with a negative connotation) one-liner, it's a normal one-liner.

    Nested ternary operators on one line are not easy to read.

    Arbitrary nested - no, but chained like else ifs look good.

    Likewise, it is always best practices to use the same numbers that are presented in the logic. If the company policy reads "7 or more days" the code should show >= 7, not >6.

    True. This is probably worse than anything else about this solution.
    (d isn't the best name either, but that's form the initial solution.)

  • Default User Avatar

    For people learning to code, they should know that this is NOT best practice.
    When working with other people on a large code base, clever one liners are not the answer. That is the reason that there are "clever" and "best practices" buttons.

    Nested ternary operators on one line are not easy to read. If I tried to check in a nested ternary operator, a code reviewer would reject my code.
    Likewise, it is always best practices to use the same numbers that are presented in the logic. If the company policy reads "7 or more days" the code should show >= 7, not >6.
    This will help people make changes later in the event that the policy changes. There is a tendency on this website to never use >= or <= and just subtract 1 from integers in order to save a character.
    This is called "code golf" and it is fun and clever, but not best practice.

    Here is a style guide for c#:
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions

  • Custom User Avatar

    It is equivalent to the ifelse statement, and it exists in many languages.
    It's the first choice for lazy people (like me) ;-)

  • Custom User Avatar

    Although, i like your solution.
    But i have a question. Is it good practice to right this type of code?
    I mean this is not so readable and understandable as compare to basic if else, but it will be efficient i guess.
    My main question is where we use these type of logics where we can use if else? What is the benefit? How they help in industry ?

  • Default User Avatar

    Expected: "S O S"
    But was: "SO S"

    Expected: "E E"
    But was: "EE"

    I've got 3 test cases wrong, (the second one twice) and I don't know why.
    And I removed with the Trim() method (C#) the white spaces before and after the input.
    What's the problem?

  • Custom User Avatar

    Oh! Thanks for quick reply. Working now :)

  • Custom User Avatar

    NOTE: Extra spaces before or after the code have no meaning and should be ignored.

    Check that.

  • Custom User Avatar

    Got 'undefinedEundefined', expected 'E'
    Got 'undefined E Eundefined', expected 'E E'

    Can anyone help me out, What decodes to undefined in morse code? This is only happening in more complex tests i have passed all the above tests.

  • Default User Avatar

    First time submitting an issue, hope I'm not going about it the wrong way.

    Final fixed test recipe is:

    { oil: '3 tbsp', flour: '2 cup', sugar: '0.5', milk: '1 cup' }

    'Sugar' has no unit. Instructions don't seem to cover missing units.

  • Custom User Avatar

    You can bake a basic cake is using the following ingredients

    Corrected:
    You can bake a basic cake by using the following ingredients