题解 | #颜色字符串转换#
颜色字符串转换
https://www.nowcoder.com/practice/80b08802a833419f9c4ccc6e042c1cca
function rgb2hex(sRGB) { const rgb=sRGB.match(/\d+/g) if(!rgb||rgb.length!=3){ return sRGB } let res='#' rgb.forEach((el)=>{ const p= parseInt(el).toString(16,2) res+=p.length==2?p:'0'+p }) return res }