54.simpleCompression

Write a function named simpleCompression that receives a string made up of letters as a parameter, let's call it text.

The function should "compress" the text parameter according to this algorithm:

  1. If the text is empty, return an empty string.

  2. If text is not empty, then:

    1. Split it into sub-strings where all characters are the same
    2. Replace each of those sub-strings with the character and the number of times it appears. (unless it only appears once, then leave it as is)
    3. Concatenate all the sub-strings and return the result.

Example 1

Input

text

=

Output