implement convertToObject#4972
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because, while your function produces the correct output, it currently violates explicit checklist constraints that are considered core requirements for this task. In src/convertToObject.js, you build the styles object by first declaring it outside the iteration and then mutating it inside a for...of loop; this conflicts with the requirement to (1) avoid mutating an already existing object via iteration methods [CHECKLIST ITEM #1] and (2) avoid using loops in favor of array iteration methods like reduce [CHECKLIST ITEM #5]. To fix this, refactor the code so that you call something like declarations.reduce(...) and return the accumulated styles object from the reducer, instead of modifying an external styles variable inside a loop.
Additionally, your JSDoc uses @return {object}, which goes against the guideline to avoid the generic object name [CHECKLIST ITEM #2]; update it to a more explicit structural type, for example @return {{[key: string]: string}}, or another clear shape that describes the returned object. The parsing logic itself—splitting on ;, filtering out empty entries, splitting on :, trimming key and value—is solid and aligns well with the functional requirements. Once you switch to an iteration method-based approach and adjust the JSDoc type, your solution will meet both the functional and checklist requirements, and you’ll be in great shape.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| */ | ||
| function convertToObject(sourceString) { | ||
| // write your code here | ||
| const styles = {}; |
There was a problem hiding this comment.
This line initializes an external object and later gets mutated inside the loop. This conflicts with checklist item #1: "Don't use iteration methods to modify an already existing array/object"—for this task you should build the object via the return value of an iteration method (like reduce) rather than mutate an external accumulator.
| .split(';') | ||
| .filter(piece => piece.trim()); | ||
|
|
||
| for (const declaration of declarations) { |
There was a problem hiding this comment.
Using a for ... of loop violates checklist item #5: "Avoid using loops in this task, use iteration methods instead." Consider using reduce (or similar) on declarations to build and return the styles object.
No description provided.