Example:
I\'m trying to figure out the calculation for finding the percentage between two values that a third value is.
Example: The range is 46 to 195. The va
If you want to calculate the percentages of a list of values and truncate the values between a max and min you can do something like this:
private getPercentages(arr:number[], min:number=0, max:number=100): number[] {
let maxValue = Math.max( ...arr );
return arr.map((el)=>{
let percent = el * 100 / maxValue;
return percent * ((max - min) / 100) + min;
});
};
Here the function call:
this.getPercentages([20,30,80,200],20,50);
would return
[23, 24.5, 32, 50]
where the percentages are relative and placed between the min and max value.