1const range = (min, max) => [...Array(max - min + 1).keys()].map(i => i + min);
2//or
3const range = (min, max) => Array.from({ length: max - min + 1 }, (_, i) => min + i);
4
5range(5, 10); // [5, 6, 7, 8, 9, 10]
1var list = [];
2for (var i = lowEnd; i <= highEnd; i++) {
3 list.push(i);
4}
1//es6
2console.log(
3 Array.from({length:5},(val,ind)=>ind)
4)
5
6//also es6
7console.log(
8 [...Array(5),keys()];
9)
1const range = (start, end, step = 1) => {
2 let output = [];
3
4 if (typeof end === 'undefined') {
5 end = start;
6 start = 0;
7 }
8
9 for (let i = start; i < end; i += step) {
10 output.push(i);
11 }
12
13 return output;
14};