-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
results #1530
Conversation
maxmodrr
commented
Oct 16, 2024
- DEMO LINK
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.
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! ✨
src/scripts/main.js
Outdated
const total = value | ||
.reduce((sum, elem) => sum + elem, 0) | ||
.toLocaleString('en-Us'); |
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.
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.
src/scripts/main.js
Outdated
.reduce((sum, elem) => sum + elem, 0) | ||
.toLocaleString('en-Us'); | ||
|
||
const average = Math.round(total / value.length).toLocaleString('en-Us'); |
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.
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.
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 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(',', '')); |
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.
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'); |
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.
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'); |
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.
The locale string 'en-Us' should be 'en-US' to correctly specify the English language locale for the United States.