Looping Arrays, Breaking and Continuing
Let's bring back the
populationsarray from a previous assignment.Use a
forloop to compute an array calledpercentages2containing the percentages of the world population for the 4 population values. Use the functionpercentageWOrld1that you created earlier.Confirm that
percentages2contains exactly the same values as thepercentagesarray that we created manually in the previous assignment, and reflect on how much better this solution is.
const populations = [10, 1441, 332, 83];
const percentages2 = [];
for (let i = 0; i < populations.length; i++) {
const perc = percentageOfWorld1(populations[i]);
percentages2.push(perc);
}
console.log(percentages2);