Created
July 3, 2015 20:08
-
-
Save arcesino/8eb6d68dcba33f2d0c80 to your computer and use it in GitHub Desktop.
Given an array of non-repeated numbers check whether the numbers are consecutive.
This file contains hidden or 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
var isConsecutiveArray = function(numbers) { | |
var min = numbers[0], | |
max = numbers[0] | |
n = numbers.length; | |
for (var i = 1; i < n; i++) { | |
if (numbers[i] < min) min = numbers[i]; | |
if (numbers[i] > max) max = numbers[i]; | |
} | |
return (max - min + 1) == n; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment