CtCI-6th-Edition-JavaScript
CtCI-6th-Edition-JavaScript copied to clipboard
Update strComp.js
It is a simpler implementation and which is more easier to read in my opinion.
The one in the original code counts a single character as 1.
console.log('aabcccccaaa', compress('aabcccccaaa'), 'a2b1c5a3');
As you can see b1 is present in the original code.
As far as other test cases,abbbbc would become a1b4c1 which is the same length as the original and hence the original is returned. So is the case for a1b3c2 as the length is same as that of original in which case the original is returned.