Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript utility belt
//A continual schmorgasboard of code that probably exists in a better documented & executed function elsewhere.
//Produces a # between min and max.
function between(min,max) {
var d = Math.abs(min - max);
return min + Math.random() * d;
}
//Integer between min & max.
function intBetween(min,max) {
return Math.floor(between(min,max))
}
function mapValue(per, min, max) {
var diff = max - min;
return min + (diff * per * 2);
}
//Produces a number from 0 - max
function ranRange(max) {
return -max + (Math.random() * (max * 2));
}
//Degrees to radians.
function deg2rad(d) {
return d * (Math.PI / 180);
}
//The other way around.
function rad2deg(r) {
return r * (180 / Math.PI);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment