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_compressor
directory that you have downloaded in the previous lesson:If you are on
is_palindrome
directory, go back one step:cd ..
And navigate to
string_compressor
directory:cd string_compressor
Once you are in the folder in the terminal, run the following command:
bundle install
Next, run the following command:
rspec
This 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.rb
located insidestring_compressor/lib
.You should see code like this:
def string_compressor(string) # Write your code here! end
Implement your solution in this file.
Once you have implemented the solution, go into your terminal and run this command again:
rspec
If your solution is correct, you should see all of the tests pass.
Good luck!