Skip to content

Instantly share code, notes, and snippets.

@nekoTheShadow
Last active January 17, 2017 08:01
Show Gist options
  • Save nekoTheShadow/22cb6ddd297945ef744b to your computer and use it in GitHub Desktop.
Save nekoTheShadow/22cb6ddd297945ef744b to your computer and use it in GitHub Desktop.
range2array = function(num1,num2){
if (num1 > num2){
temp = num1;
num1 = num2;
num2 = temp;
}
var ary = [];
for(var i = num1; i <= num2; i++){
ary.push(i);
}
return ary
}
// == main ==
console.log(range2array(1,10));
// => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
console.log(range2array(-3,8));
// => [ -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
console.log(range2array(10,2));
// => [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
console.log(range2array(5,5));
// => [ 5 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment