Let's say I have this array of numbers:
$arr = [100, 60, 30, 22, 1]
and it's based off a 1 - 100
range. And I want it based of a 1 - 5
range.
I have found this answer here: How to scale down a range of numbers with a known min and max value which details:
Array.prototype.scaleBetween = function(scaledMin, scaledMax) {
var max = Math.max.apply(Math, this);
var min = Math.min.apply(Math, this);
return this.map(num => (scaledMax-scaledMin)*(num-min)/(max-min)+scaledMin);
}
But I am not sure how I would translate that to PHP/Laravel.