挑战优雅写法
function rgb2hex(sRGB) {
if (!/^rgb\((\d{1,3},\s*){2}\d{1,3}\)$/.test(sRGB)) return sRGB;
let color = '#';
sRGB.replace(/\d+/g, n => color += ('0' + (+n).toString(16)).slice(-2));
return color;
}
function rgb2hex(sRGB) {
if (!/^rgb\((\d{1,3},\s*){2}\d{1,3}\)$/.test(sRGB)) return sRGB;
let color = '#';
sRGB.replace(/\d+/g, n => color += ('0' + (+n).toString(16)).slice(-2));
return color;
}