so how to make such logic
int[] arr = {2, 5, 3};
if (/* arr is sorted */)
....
else
...
Its bad that method Array.sort is void
A shorter version:
[0,1,2,3,4].reduce((a,v) => (a!==false) && (a <= v) ? v : false, -Infinity)
[4,3,1,2,0].reduce((a,v) => (a!==false) && (a >= v) ? v : false, +Infinity)
Be careful, as in some cases it isn't effective because it will loop through entire array without breaking prematurely.
Array.prototype.reduce()