1.6 Length bug
The way that string length is compared and calculated is not correct when strings have significant entropy. See my branch showing this here @tankwan
Do you want to fix this @tankwan? I can if not.
Hey @dawsbot, hope you're having a great weekend! Sure thing, I can take care of it :)
On Sun, 21 May 2017 at 14:02 Dawson Botsford [email protected] wrote:
Do you want to fix this @tankwan https://github.com/tankwan? I can if not.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/careercup/CtCI-6th-Edition-JavaScript/issues/14#issuecomment-302963057, or mute the thread https://github.com/notifications/unsubscribe-auth/AEhn5XRlVvasQXycgtMpLJwhFUE1HGjHks5r8KZ_gaJpZM4NhuTU .
@thetonytan - ping!
Bug in this test
console.log('aabbcc', strComp('aabbcc'), 'aabbcc')
As the book says, if the length of the result is not less than the original should print the original, and it is printing:
a2b2c2
I don't see why use the Math.max()... I would go this way
var strComp = function(string) {
var compressed = '';
var currChar = '';
var currCount = '';
for (var i = 0; i < string.length; i++) {
if (currChar !== string[i]) {
compressed = compressed + currChar + currCount;
currChar = string[i];
currCount = 1;
} else {
currCount++;
}
}
compressed = compressed + currChar + currCount;
return compressed.length >= string.length ? string : compressed;
};