Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #3682

wants to merge 2 commits into from

Conversation

save-v
Copy link

@save-v save-v commented Nov 6, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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! ✨

@@ -6,7 +6,20 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
let res = sourceString.split(';');

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.

// write your code here
let res = sourceString.split(';');

res = res.map((el) => el.split(':'));

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.


res = res.map((el) => el.split(':'));
res = res.map((el) => el.map((item) => item.trim()));
res = res.filter((item) => item.length > 1);

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.

Copy link

@BudnikOleksii BudnikOleksii left a 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

Comment on lines 9 to 13
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);

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

@save-v save-v requested a review from BudnikOleksii November 7, 2024 17:43
Copy link

@Moroz-Dmytro Moroz-Dmytro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants