Assertive programming kata

Story points 3
Hard Prerequisites
  • TOPICS: Introduction to assertive programming

  • These katas are a bit harder than the last bunch. Make use of assertions to help make sure that your code is doing the right thing, and to add readability.

    Exercise: Morse code

    Create two functions:

    lettersToMorseCode
    morseCodeToLetters
    

    eg:

    lettersToMoreseCode("Hi there")
    // should return
    // ".... .. / - .... . .-. ."
    

    Include the following assertions in your code:

    • assert that the output and input both have the same number of characters represented
    • assert that there are the right number of spaces represented in the output

    Make sure that when you do this, your code remains clean and DRY. DRY - it’s a thing. Google it.

    Resources

    Remarks

    Admittedly this kata is a little bit contrived. Assertions are great for adding runtime checks to values and adding documentation as code.

    For a problem like this one, unit tests are more appropriate.

    Up for a challenge?

    Add unit tests to your code. Leave the asserions in there just so that we can see that you know how to hit the requirements we laid out. But if you have some passing tests as well that would be sweet.


    RAW CONTENT URL