Fastest way of finding the middle value of a triple?

前端 未结 25 971
庸人自扰
庸人自扰 2020-12-04 12:20

Given is an array of three numeric values and I\'d like to know the middle value of the three.

The question is, what is the fastest way of finding the midd

25条回答
  •  天涯浪人
    2020-12-04 12:52

    You might as well write this in the most straightforward, way. As you said, there are only six possibilities. No reasonable approach is going to be any faster or slower, so just go for something easy to read.

    I'd use min() and max() for conciseness, but three nested if/thens would be just as good, I think.

提交回复
热议问题