Last active
January 17, 2017 08:01
-
-
Save nekoTheShadow/22cb6ddd297945ef744b to your computer and use it in GitHub Desktop.
This file contains 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
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