Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on this solution! All the functional requirements have been met. The code successfully parses the data from the DOM, calculates the total and average population, and updates the page with the correctly formatted numbers.
As a point for future improvement, consider making the code more efficient. Currently, you iterate over the data twice: once with forEach and again with a for loop. These can be combined into a single loop where you calculate the sum directly, which would be more performant and concise. Since the code is fully functional, I am approving your submission. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| for (let i = 0; i < result.length; i++) { | ||
| sum += result[i]; | ||
| average = sum / result.length; | ||
| } |
There was a problem hiding this comment.
You're iterating over the data twice: once with forEach to build the result array, and a second time with this for loop to calculate the sum. These can be combined for better efficiency. Try calculating the sum directly inside the forEach loop. This way, you avoid creating an unnecessary result array and a second loop. The average can then be calculated once after the forEach loop is complete.
No description provided.