JSFiddle - React, Tailwind, and code Playground
by Glutamat
JavaScript
function createRange(arr) {
var result = [], //The resulting array
range;
for (var i = 0; i < arr.length; i++) {//Iterate over the array
if (Array.isArray(arr[i])) { //If we find another array
range = arr [i];
for (var j=range [0]; j <= range [1]; j++) {//increase its first element until it's equal the second
result.push(j); //add the number to the resulting array
}
} else { //If it's a number
result.push(arr[i]); //put it in the resulting array
}
}
return result; //return the array containing the range
}
console.log(createRange([
[1, 5], 10, [15, 20]
])) //[1, 2, 3, 4, 5, 10, 15, 16, 17, 18, 19, 20]