I'm trying to make a simple daily follower stats like the screenshot below.
And here's the code I'm using.
const normalize = ({ min, max, number }) => {
return parseFloat((((number - min) / (max - min)) * 100).toFixed(2))
}
const followers = {
'03-23-2022': 2115,
'03-24-2022': 2128,
'03-25-2022': 2175,
'03-26-2022': 2195,
'03-27-2022': 2215,
'03-28-2022': 2206,
'03-29-2022': 2258
}
const numbers = []
for (const day in followers) {
const stats = followers[day]
numbers.push(stats)
}
const min = Math.min.apply(null, numbers)
const max = Math.max.apply(null, numbers)
for (const day in followers) {
const activity = followers[day]
const percent = normalize({ min, max, number: activity })
console.log({ day, activity, percent })
}
As you can see on the console log the normalize function returns 0 for the minimum number and that's why nothing is visible on the site.
What I'd like to do is I want to get some meaningful numbers from the normalize function to be able to show the stats in a more readable style. How do I do that?