so how to make such logic
int[] arr = {2, 5, 3}; if (/* arr is sorted */) .... else ...
Its bad that method Array.sort is void
You can use .every
.every
let isSorted = array.every((v, i) => (i === 0 || v <= array[i - 1])) || array.every((v, i) => (i === 0 || v >= array[i - 1]))