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
/** Whether we are using a Mac or not. */ | |
function isMac() { | |
return /Mac/.test(navigator.platform); | |
} | |
/** Whether this is on the Windows platform or not. */ | |
function isWindows() { | |
return /Win/.test(navigator.platform); | |
} |
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
// Getting a random number between 0 (inclusive) and 1 (exclusive) | |
function getRandom() { | |
return Math.random(); | |
} | |
// Getting a random number between two values | |
function getRandomArbitrary(min, max) { | |
return Math.random() * (max - min) + min; | |
} |
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
function swapDomNodes(a, b) { | |
var afterA = a.nextSibling; | |
if (afterA == b) { | |
swapDomNodes(b, a); | |
return; | |
} | |
var aParent = a.parentNode; | |
b.parentNode.replaceChild(a, b); | |
aParent.insertBefore(b, afterA); | |
} |
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
function round(number, places) { | |
places = Math.max(0, Math.min(places || 0, String(number).split(".")[1].length || 0)); | |
return Math.round(number * Math.pow(10, places)) / Math.pow(10, places); | |
} |
NewerOlder