Skip to content

Instantly share code, notes, and snippets.

@SankaitLaroiya
Last active March 9, 2018 21:54
Show Gist options
  • Save SankaitLaroiya/fca8814c4f3b822c6aa6416bb2e83ebb to your computer and use it in GitHub Desktop.
Save SankaitLaroiya/fca8814c4f3b822c6aa6416bb2e83ebb to your computer and use it in GitHub Desktop.
(JS) Scale Numbers Between a Given Range
// Code snippet taken from:
// https://stackoverflow.com/a/31687097
function scaleBetween(unscaledNum, minAllowed, maxAllowed, min, max) {
return (maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment