Shortening a Javascript if-else structure

前端 未结 7 812
情书的邮戳
情书的邮戳 2021-02-13 00:05

The code I have is:

 var level = function (d) {
    if (value(d) > median + stdev) {
        return 1;
    } else if (value(d) > median) {
        return 2         


        
相关标签:
7条回答
  • 2021-02-13 00:34

    This solution is nicer, but I would not recommend using it in production as it is kind of confusing:

    4 - [median + stdev, median, median - stdev].filter(function(e, i, a) {
        return value(d) > e;
    }).length 
    
    0 讨论(0)
提交回复
热议问题