I read this, but it doesn't apply (and/or, I can't figure out how to adapt the solutions). I also found this, but I don't want to change the array - I just want to check the information. I was unable to adapt the solutions to fit my needs.
I want to find out of the values in a Javascript Array are Sequential.
For example - I have an array of UNIX timestamps
var ts = [1451772000, 1451858400, 1452031200]
I want to return true if they are sequential (lower to higher values) and false if they are not sequential. I would also like to return false if there are duplicate values.
O(n), orO(1)in the best-case (the very first pair of values are in the wrong order).0ton-1and for each element compare theith element to thei+1element with<. If that's false, quit early and return false (they aren't in the right order). If you make it to the end of the array, then they are all in order, return true.