Run-Length Encoding

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write encode(text): replace each run of the same character with that character followed by the length of the run, written in full. "aaabcc" becomes "a3b1c2", and twelve x's become "x12". A character that comes back later starts a new run, and upper and lower case are different characters. Empty text gives an empty string.

Your code must pass

  • Writes each run as the character and its count
  • Starts a new run when a character comes back
  • Writes counts of 10 or more in full
  • Treats upper and lower case as different
  • Returns an empty string for empty text