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

results #1530

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

results #1530

wants to merge 2 commits into from

Conversation

maxmodrr
Copy link

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.

The current implementation has critical issues with the calculation of the average and total, which affect the functionality of the code. Please address these issues to ensure accurate calculations. Keep up the good work, and don't hesitate to reach out if you need help! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines 12 to 14
const total = value
.reduce((sum, elem) => sum + elem, 0)
.toLocaleString('en-Us');

Choose a reason for hiding this comment

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

There is an issue with the calculation of the total. The reduce method is correctly used to sum up the values, but the result of reduce should be converted to a string using toLocaleString after the sum is calculated, not during the chaining. Consider storing the result of reduce in a variable before converting it to a localized string.

.reduce((sum, elem) => sum + elem, 0)
.toLocaleString('en-Us');

const average = Math.round(total / value.length).toLocaleString('en-Us');

Choose a reason for hiding this comment

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

The calculation of the average is incorrect because total is currently a localized string, not a number. You should calculate the average using the numeric total before converting it to a localized string.

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 the pull request! 🎉 The issues mentioned are minor and don't critically impact the functionality. Keep up the good work and consider the suggestions for future improvements!

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

const textTotal = bodyElement.querySelector('.total-population');
const textAverage = bodyElement.querySelector('.average-population');

const value = population.map((elem) => +elem.textContent.replaceAll(',', ''));

Choose a reason for hiding this comment

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

The use of replaceAll might not be supported in all environments. Consider using replace with a global regular expression instead for better compatibility.

const total = value.reduce((sum, elem) => sum + elem, 0);
const average = Math.round(total / value.length);

textTotal.textContent = total.toLocaleString('en-Us');

Choose a reason for hiding this comment

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

The locale string 'en-Us' should be 'en-US' to correctly specify the English language locale for the United States.

const average = Math.round(total / value.length);

textTotal.textContent = total.toLocaleString('en-Us');
textAverage.textContent = average.toLocaleString('en-Us');

Choose a reason for hiding this comment

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

The locale string 'en-Us' should be 'en-US' to correctly specify the English language locale for the United States.

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.

2 participants