Skip to content

Instantly share code, notes, and snippets.

@manegame
Last active June 2, 2019 12:20
Show Gist options
  • Save manegame/be803f7d294dd5badaa8be6227e3a169 to your computer and use it in GitHub Desktop.
Save manegame/be803f7d294dd5badaa8be6227e3a169 to your computer and use it in GitHub Desktop.
/**
*
* @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