-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #2755
base: master
Are you sure you want to change the base?
Solution #2755
Conversation
src/convertToObject.js
Outdated
arrayFromString = arrayFromString.map( | ||
line => line.replace('.2s', ' .2s ')); | ||
|
||
arrayFromString = arrayFromString.map( | ||
line => line.replace('solid', ' solid ')); | ||
arrayFromString = arrayFromString.map(line => line.replace('!', ' !')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the styles have different values than .2s
or solid
? Will your code still work? It is not necessary to do it this way.
Btw. you are iterating through the array way more times than it's necessary. Try to find a simpler solution. I'm sure you are gonna solve with way less steps ;)
That's my best shot, I hope it's enough 😁 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
This is a hardcore and very slow solution (regex'es are slow).
What I would do is:
- replace newlines and split over ';'
- for every part I would trim it, split it on ':' and destructure like
[key, value] = trimmed
- If i have key and value, just append it to the returning object.
Your solution won't be accepted using regexes because it is unnecessary slow.
Due to the fact that Marcin raised a complaint to my review I'm forced to revoke my assessment and add a new one with following comment: I based my assessment on the fact that regexes have varying computational complexity and, depending on the syntax, they can have either linear or exponential (if we use backtracking). Your regexes just happen to have a linear one. |
No description provided.