Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
Created August 9, 2023 12:52
Show Gist options
  • Save quidmonkey/19f407d6e9ee2660a5eb78baf4ce8b1c to your computer and use it in GitHub Desktop.
Save quidmonkey/19f407d6e9ee2660a5eb78baf4ce8b1c to your computer and use it in GitHub Desktop.
Map a Number from One Value System to Another
Number.prototype.map = (istart, istop, ostart, ostop) => {
return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
};
const map = (value, istart, istop, ostart, ostop) => {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment