is-sorted-g
Version:
A small module to check if an Array is sorted, study from dcousens/is-sorted
19 lines (16 loc) • 383 B
JavaScript
/**
* @argument {Number} a
* @argument {Number} b
*/
const defaultComparator = (a, b) => a - b
/**
* @argument {Array} array
* @argument {Function} comparator
*/
const checksort = (array, comparator = defaultComparator) => {
let prev = array.shift()
return array.every(next => {
return !(comparator(prev, next) > 0) && (prev = next)
})
}
module.exports = checksort