How can we show the score on a scale of 1 to 10 rather than showing it from 0 to 1 #558
shubham5526
started this conversation in
General
Replies: 1 comment
-
The scores are those because decimals solve all humanity's problem. But do read about Fuse.js scoring theory to understand why that's the case 😄 Nonetheless, what you're trying to do is the problem of "given a range of values between A and B, we want to map them into a different range of values between C and D". This is called linear mapping. The formula would essentially be: const inputStart = 0 // The lowest number of the range input.
const inputEnd = 1 // The largest number of the range input.
const outputStart = 1 // The lowest number of the range output.
const outputEnd = 10 // The largest number of the range output.
function getValue(input) {
return (input - inputStart) / (inputEnd - inputStart) * (outputEnd - outputStart) + outputStart
} getValue(0) // => 1
getValue(0.1) // => 1.9
getValue(0.2) // => 2.8
getValue(0.3) // => 3.6999999999999997
getValue(0.4) // => 4.6
getValue(0.5) // => 5.5
getValue(0.6) // => 6.3999999999999995
getValue(0.7) // => 7.3
getValue(0.8) // => 8.2
getValue(0.9) // => 9.1
getValue(1) // => 10 Now, if you want to reverse it, so that const outputStart = 10
const outputEnd = 1 getValue(0) // => 10
getValue(0.1) // => 9.1
getValue(0.2) // => 8.2
getValue(0.3) // => 7.300000000000001
getValue(0.4) // => 6.4
getValue(0.5) // => 5.5
getValue(0.6) // => 4.6000000000000005
getValue(0.7) // => 3.7
getValue(0.8) // => 2.8
getValue(0.9) // => 1.9000000000000004
getValue(1) // => 1 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to show the score on UI and those decimal values do not make any sense to the user. Like 0.000000126564.
So, is there a way I can show the score as between 1 to 10?
Beta Was this translation helpful? Give feedback.
All reactions