array-sorted
Version:
check an array is sorted or not.
16 lines (13 loc) • 324 B
JavaScript
module.exports = (
array,
compare = (a, b) => {
return a > b;
}
) => {
if (!Array.isArray(array))
throw new TypeError('Only array can sort, this is ' + typeof array);
for (let i = 1, length = array.length; i < length; ++i) {
if (compare(array[i - 1], array[i])) return false;
}
return true;
};