if(first - second >=2 || first - second <=-2 || first - third >=2 || first - third <=-2 || second - third >=2 || second - third <=-2)
真恶心。
我有三个值需要检查,如果其中任意两个值的差 >= 2,那么我将执行一些任务。
我很好奇,你能建议一种让这更愉快的方法吗?谢谢
最佳答案
if ( Math.max(first, second, third) - Math.min(first, second, third) >= 2 )
或者效率低一点:
var a = [first, second, third].sort((a, b) => a - b));
if ( a[2] - a[0] >= 2 )
关于javascript - 有没有更优雅的方式来写这些条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51698390/