Comments (5)
from ctci-6th-edition-javascript.
@thetonytan - ping!
from ctci-6th-edition-javascript.
Do you want to fix this @tankwan? I can if not.
from ctci-6th-edition-javascript.
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
from ctci-6th-edition-javascript.
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;
};
from ctci-6th-edition-javascript.
Related Issues (14)
- Pushing different solutions
- Add new contributor & remove me HOT 3
- chapter01/1.3 - URLify/urlify.js HOT 4
- My variant of the Urlify problem.
- Update ch1-q1? HOT 1
- maintenance: add linter as part of the CI HOT 1
- fix variable name for 3.3-stackOfPlates.js
- chore: add CONTRIBUTING.md file
- Mismatch in question 2.8 (loop detection in linked list)
- Test
- Test with CI HOT 2
- 8.12 N Queens has solution to a different problem HOT 1
- 1.6 String Comparison Error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ctci-6th-edition-javascript.