This file contains hidden or 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
// assume positive integers as parameters | |
function getDigit(n, d) { | |
return parseInt( n / Math.pow(10, d - 1), 10 ) % 10; | |
} | |
function nth(n) { | |
var d1 = getDigit(n, 1); | |
var d2 = getDigit(n, 2); | |
n = "" + n; |
This file contains hidden or 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
// midnight today | |
var today = new Date(new Date().setHours(0,0,0,0)); | |
// midnight tomorrow | |
var tomorrow = new Date(new Date().setHours(24,0,0,0)); | |
// date format: yyyy-mm-dd HH:MM:SS | |
function pad(n, width, z) { | |
z = z || '0'; | |
n = n + ''; |
This file contains hidden or 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 toHex(n: number) { | |
return ('0' + n.toString(16)).slice(-2); | |
} | |
// ES6 | |
function hexToRGB(code) { | |
const [r, g, b] = code.replace('#', '') | |
.match(/../g).map((hex) => parseInt(hex, 16)); | |
return {r, g, b}; |
NewerOlder