Skip to content

Instantly share code, notes, and snippets.

@arcesino
Created July 3, 2015 20:08
Show Gist options
  • Save arcesino/8eb6d68dcba33f2d0c80 to your computer and use it in GitHub Desktop.
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.
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