CtCI-6th-Edition-JavaScript icon indicating copy to clipboard operation
CtCI-6th-Edition-JavaScript copied to clipboard

Update strComp.js

Open AmitJoki opened this issue 6 years ago • 2 comments

AmitJoki avatar May 16 '19 06:05 AmitJoki

It is a simpler implementation and which is more easier to read in my opinion.

AmitJoki avatar Aug 26 '19 01:08 AmitJoki

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.

AmitJoki avatar Aug 26 '19 13:08 AmitJoki