Last active
June 2, 2019 12:20
-
-
Save manegame/be803f7d294dd5badaa8be6227e3a169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {Number} num | |
* @param {Number} in_min | |
* @param {Number} in_max | |
* @param {Number} out_min | |
* @param {Number} out_max | |
*/ | |
mapValues(num, in_min, in_max, out_min, out_max) { | |
return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min | |
} | |
/** | |
* If we have a scoring range of max 60 min 20, we could do: | |
* | |
*/ | |
let scores = [ 60, 40, 36, 32, 30, 20 ] | |
let max = Math.max(scores) | |
let min = Math.min(scores) | |
let mappedScores = scores.forEach(score => { | |
return mapValues(score, max, min, 50, 100) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment