题解 | #颜色字符串转换#
颜色字符串转换
https://www.nowcoder.com/practice/80b08802a833419f9c4ccc6e042c1cca
function rgb2hex(sRGB) { let tr=sRGB.split('(')[1] ||'' let tl=tr.split(')')[0] ||'' let t=tl.split(',')||'' if(t.length!==3) return sRGB let res='#' t.forEach((el)=>{ let tem=parseInt(el).toString(16) res+=tem.length==1?'0'+tem:tem }) return res }