Is there a more concise and readable way to write a function that checks if a given number is smaller, larger, or between two other numbers? The function should return NaN if any of the input parameters are not numbers.
function order(num, a, b) {
if (a > b) {
return NaN;
}
if (num < a) {
return -1;
}
if (num > b) {
return 1;
}
if (a <= num && num <= b) {
return 0;
}
return NaN;
}
// Use case examples
console.log(order(5, 10, 20));
console.log(order(10, 10, 20));
console.log(order(15, 10, 20));
console.log(order(20, 10, 20));
console.log(order(25, 10, 20));
console.log(order(15, 20, 10));
console.log(order(15, 10, undefined));
console.log(order(15, undefined, 20));
console.log(order(15, undefined, undefined));
console.log(order(undefined, 10, 20));