Skip to content

Instantly share code, notes, and snippets.

View avisek's full-sized avatar

Avisek Das avisek

  • Planet Earth
View GitHub Profile
/** 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);
}
// 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;
}
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);
}
@avisek
avisek / round.js
Last active October 7, 2018 18:50
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);
}