Last active
March 31, 2019 14:07
-
-
Save ZackFox/76d7f1f11605314638f24df88c49ba32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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