function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function hexToRgb(hex, result = /^#?([a-fd]{2})([a-fd]{2})([a-fd]{2})$/i.exec(hex)) {
return result ? result.map(i => parseInt(i, 16)).slice(1) : null
//returns [23, 14, 45] -> reformat if needed
}
console.log(rgbToHex(10, 54, 120)); // #0a3678
console.log(hexToRgb("#0a3678")); // [10, 54, 120]