题解 | #颜色字符串转换#

颜色字符串转换

http://www.nowcoder.com/practice/80b08802a833419f9c4ccc6e042c1cca

function rgb2hex(sRGB) {
    let str = '#'
    var temp
    sRGB.slice(4, -1).split(',').forEach((value) => {
        temp = parseInt(value.trim()).toString(16)
        str += temp.length == 1 ? '0' + temp : temp
    })
    if (str === '#NaN') return sRGB
    return str
}
全部评论

相关推荐

下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务