Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabccccaaa would become a2b1c5a3. If the compressed string is smaller than the original string, your method should return the compressed string. You can assume the string has only uppercase and lowercase letters (a-z).
Getting Started
First, navigate to the
string_compressordirectory that you have downloaded in the previous lesson:If you are on
is_palindromedirectory, go back one step:cd ..And navigate to
string_compressordirectory:cd string_compressorOnce you are in the folder in the terminal, run the following command:
bundle installNext, run the following command:
rspecThis will run some tests to see if your code is working. Since you haven't written any code yet, you will see that all of the tests fail.
Next, open up your text editor and open
string_compressor.rblocated insidestring_compressor/lib.You should see code like this:
def string_compressor(string) # Write your code here! endImplement your solution in this file.
Once you have implemented the solution, go into your terminal and run this command again:
rspecIf your solution is correct, you should see all of the tests pass.
Good luck!