Skip to content

Instantly share code, notes, and snippets.

@ZackFox
Last active March 31, 2019 14:07
Show Gist options
  • Save ZackFox/76d7f1f11605314638f24df88c49ba32 to your computer and use it in GitHub Desktop.
Save ZackFox/76d7f1f11605314638f24df88c49ba32 to your computer and use it in GitHub Desktop.
Array.prototype.isSorted = function () {
if(this.length < 2) return false;
let dir = this[0] < this[1] ? 1 : -1;
for(let i = 1; i < this.length-1; i++) {
if(dir === 1 && this[i] > this[i+1]) {
return false;
}
if(dir === -1 && this[i] < this[i+1]) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment