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 #3687

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
* @return {object}
*/
function convertToObject(sourceString) {
// write your code here
const newSource = sourceString
.split(';')
.map((sourceString) => sourceString.trim())

Check failure on line 11 in src/convertToObject.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'sourceString' is already declared in the upper scope on line 8 column 26
.filter((sourceString) => sourceString.length > 0);

Check failure on line 12 in src/convertToObject.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'sourceString' is already declared in the upper scope on line 8 column 26

const newLine = newSource.map((line) => line.split(':'));

newLine.sort();

Choose a reason for hiding this comment

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

Sorting newLine is unnecessary and might lead to unexpected behavior if the order of entries is important. Consider removing this line unless sorting is explicitly required by the task.


const styleObject = Object.fromEntries(newLine);

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 always in the expected format. Consider adding error handling for cases where the input string might not contain colons or semicolons, which could lead to unexpected results.


const cleanedObject = {};

for (const key in styleObject) {
const cleanedKey = key.trim();
const cleanedValue = styleObject[key].trim();

cleanedObject[cleanedKey] = cleanedValue;
}

return cleanedObject;
}

module.exports = convertToObject;
Loading