JSFiddle - React, Tailwind, and code Playground

by Luis Perez

JavaScript

let tmp = '1,2,3,4,5-9,12,13'

tmp = tmp.split(',').map((val) => {
  let tmp = Number(val);
  if (tmp) return tmp;
 
  tmp = val.split('-');
  let tmpArr = [],
    cnt = Number(tmp[0]);
  
  while (cnt <= Number(tmp[1]))
    tmpArr.push(cnt++);
  
  return ([...tmpArr])
})
// Outputs [1, 2, 3, 4, Array(5), 12, 13]
// What i want is [1,2,3,4,5,6,7,8,9,12,13]
// How dow I get the array out of there... I can solve this with a higher hoisted array, and pushing into it, but there must be a better way...
console.log(tmp)