题解 | #颜色字符串转换#
颜色字符串转换
https://www.nowcoder.com/practice/80b08802a833419f9c4ccc6e042c1cca
function rgb2hex(sRGB) { // 填写JavaScript if(!sRGB.includes('rgb')){ return sRGB } let str=sRGB.slice(4,sRGB.length-1) let arr=str.split(',') let result='#' for(let i=0;i<arr.length;i++){ let res = parseInt(arr[i]).toString(16); //if (res.length <2) { // res=res.padStart(2, "0"); //} result = result +( res.length<2?'0'+res:res); } return result }