A somewhat painful triple-nested ternary operator

后端 未结 9 1586
北恋
北恋 2020-12-30 20:12

I went looking through Raphael.js\'s source code to find out how he converted RGB values to HSB. I found out the function he did it in and I was in the process

9条回答
  •  感动是毒
    2020-12-30 20:47

    Why not use ternary operators found in Python?

    H = (
        None            if C == 0 else
        (g - b) / C     if V == r else
        (b - r) / C + 2 if V == g else
        (r - g) / C + 4
    )
    

提交回复
热议问题