Shortening a Javascript if-else structure

前端 未结 7 817
情书的邮戳
情书的邮戳 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 
    

提交回复
热议问题