Skip to content

Instantly share code, notes, and snippets.

@keune
Created January 10, 2015 18:29
Show Gist options
  • Save keune/e9d477d219b8c61f1583 to your computer and use it in GitHub Desktop.
Save keune/e9d477d219b8c61f1583 to your computer and use it in GitHub Desktop.
Returns an array, containing integers between min and max, including min and max
/*
* Returns an array, containing integers between min and max, including min and max
*/
function range(min, max) {
if(typeof min !== 'number' || typeof max !== 'number' || isNaN(min) || isNaN(max)) return [];
if(min > max) {
var tmp = min;
min = max;
max = tmp;
}
var length = max - min + 1;
return new Array(length).join('-').split('-').map(function(el, index) {return min+index;});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment