Skip to content

Instantly share code, notes, and snippets.

@FarazPatankar
Forked from jalexy12/sequential_strings.md
Created June 7, 2017 16:09
Show Gist options
  • Save FarazPatankar/8c4bfa7b9a62b92cf4f349eac51c102c to your computer and use it in GitHub Desktop.
Save FarazPatankar/8c4bfa7b9a62b92cf4f349eac51c102c to your computer and use it in GitHub Desktop.
Sequential Strings

Letter Sequencing

In Ruby create a function that takes in a series of sequential letters, processes it, and returns a new string with the number of occurances of that letter in a row.

For instance: processString("aabbcc") should return 2a2b2c. If a letter has only one occurance, it should only add the letter itself, not 1. For instance processString("abbcc") should return a2b2c.

Letters in non sequential order should be returned as is. For instance processString("aabbccabbc") should return 2a2b2ca2bc.

Assumptions

Assume that the string being given to the function is a lowercase letter that is either a, b, c, or d.

Test Cases

All cases should print true

  p processString("abcd") == "abcd"
  p processString("aabbcc") == "2a2b2c"
  p processString("aabbccabbca") == "2a2b2ca2bca"
  p processString("aabbbcc") == "2a3b2c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment