I have a set of data: var data = [312, 91, 53, 28, 22, 13, 13, 11, 5, 3];
with a sum of 551.
I want to “normalize” this data so that the sum equals a specified input smaller or larger than the original sum.
I know that I can do this simply by dividing each number in the set by 551 and then multiplying it by my target value but this results in floats when I want my answer to consist only of integers.
var data = [312, 91, 53, 28, 22, 13, 13, 11, 5, 3];
var dataNew = [];
var target = 541;
var sum = data.reduce((a, b) => a + b)
for (var point in data) {
dataNew.push(data[point]/sum*target);
}
console.log(dataNew)
I know that this will mean that the relative weights of each data point will change slightly but that is something I can accept.
I also need to keep all original entries so no data point can be discarded during the process just set to the minimum value of 1.