-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 #3682
base: master
Are you sure you want to change the base?
Solution #3682
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.
Great job on implementing the convertToObject
function! 🎉 Your code meets the task requirements and constraints effectively. You've used descriptive variable names and leveraged iteration methods like map
and filter
correctly, which enhances readability and adheres to best practices.
Here are a few suggestions for future improvements:
- Logging Ignored Entries: Filtering items with
item.length > 1
is a smart way to handle invalid entries. Consider logging these cases to inform users about any ignored entries. - Delimiter Check: Ensure that the input string is correctly formatted with the expected delimiter
:
. This will help in creating the object as intended. - Input Validation: Adding a check to handle cases where
sourceString
might be empty or not a string can prevent potential runtime errors and make your function more robust.
Keep up the great work, and continue refining your skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/convertToObject.js
Outdated
@@ -6,7 +6,20 @@ | |||
* @return {object} | |||
*/ | |||
function convertToObject(sourceString) { | |||
// write your code here | |||
let res = sourceString.split(';'); |
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.
Consider adding a check to handle cases where sourceString
might be empty or not a string. This can prevent potential runtime errors.
src/convertToObject.js
Outdated
// write your code here | ||
let res = sourceString.split(';'); | ||
|
||
res = res.map((el) => el.split(':')); |
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.
Ensure that the input string is correctly formatted. If the string does not contain the expected delimiter ':', the resulting object might not be as intended.
src/convertToObject.js
Outdated
|
||
res = res.map((el) => el.split(':')); | ||
res = res.map((el) => el.map((item) => item.trim())); | ||
res = res.filter((item) => item.length > 1); |
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.
Filtering items with item.length > 1
is a good approach to remove invalid entries. However, consider logging or handling these cases to inform the user about ignored entries.
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.
Good work 👍
Let's improve your solution
src/convertToObject.js
Outdated
let res = sourceString.split(';'); | ||
|
||
res = res.map((el) => el.split(':')); | ||
res = res.map((el) => el.map((item) => item.trim())); | ||
res = res.filter((item) => item.length > 1); |
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.
- res/result/el/elem/obj/object/arr/array and etc are bad names, name should describe variable
- Prefer const over let, you can call all iteration method in chain
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.
👍
No description provided.