A somewhat painful triple-nested ternary operator

后端 未结 9 1526
北恋
北恋 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:46

    To my personal taste, a carefully aligned nested ternary beats the if-esle mess:

    const H =
      C == 0 ? null            :
      V == r ? (g - b) / C     :
      V == g ? (b - r) / C + 2 :
               (r - g) / C + 4 ;
    

提交回复
热议问题