-
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
initial commit #2739
base: master
Are you sure you want to change the base?
initial commit #2739
Conversation
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.
Overall good job! :) Code works and the purpose of each step is clear, but there's room to make it more compact and limit unnecessary repeating
src/convertToObject.js
Outdated
return fixedKey; | ||
}); | ||
|
||
// console.log(array); |
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.
We can get rid of unnecessary comments
src/convertToObject.js
Outdated
let array = sourceString.split(';'); | ||
|
||
if (array.length === 0) { | ||
return {}; | ||
} | ||
|
||
// let's remove unnecesary signs here (clearing array) | ||
array = array.map((key) => { | ||
return key.replace(/\n/g, '').trim(); | ||
}).filter(Boolean); | ||
|
||
// creating key:value pairs in array | ||
array = array.map((key) => { | ||
return key.split(':'); | ||
}); | ||
|
||
// cleaning inside, this time triming each element | ||
array = array.map((key) => { | ||
const fixedKey = key.map((el) => el.trim()); | ||
|
||
return fixedKey; | ||
}); |
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.
Instead of overwriting array, you could try to implement chaining of array methods
src/convertToObject.js
Outdated
array = array.map((key) => { | ||
return key.split(':'); | ||
}); | ||
|
||
// cleaning inside, this time triming each element | ||
array = array.map((key) => { | ||
const fixedKey = key.map((el) => el.trim()); | ||
|
||
return fixedKey; | ||
}); |
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.
E.g. here you could use two methods on key ( .split(...).map(...) ) while mapping the whole array only one time
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.
I totally agree with the previous reviewer. You are iterating through the array way more times than necessary.
It works, good for you ;) But I would love to see a 'cleaner' solution
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.
Looks good!
No description provided.