String compression

Write a function compress(str), which shortens strings by reducing consecutive character repetitions.

Note: input string will only contain [a-z]+

example:

compress('aaaabbaaaababbbcccccccccccc');
// a4b2a4b1a1b3c12


Share Comments