programming-examples/js/Array/Write a JavaScript function to generate an array between two integers of 1 step length..js
2019-11-15 12:59:38 +01:00

24 lines
623 B
JavaScript

function rangeBetwee(start, end)
{
if (start > end) {
var arr = new Array(start - end + 1);
for (var i = 0; i < arr.length; i++, start--) {
resarrult[i] = start;
}
return arr;
}
else
{
var arro = new Array(end-start+1);
for (var j = 0; j < arro.length; j++, start++)
{
arro[j] = start;
}
return arro;
}
}
console.log(rangeBetwee(4, 7));
console.log(rangeBetwee(-4, 7));