How I need a little help, I have the following arrangement:
And what I need is to transform quantity
in%, corresponding to the total average of all the amounts, that is:
the total sum of quantity
is 791 which is equivalent to 100%
then 656 would correspond to 83%, 31 would correspond to 4% and so on until we have all the% in the same arrangement,
- Sumar todo para obtener cada %
- Multiplicar el numero x 100 y divido por la suma total
How would you apply it with the smallest possible code in javascript?
I have the following code, but it does not give me what I want.
totalLocation = 0;
firstsix.forEach(element => {
totalLocation = totalLocation + element.quantity;
console.log(element.quantity * 100 / totalLocation)
})