title: Javascript: Convert string to array of objects?
body: <p>Tell me, how can I optimally convert a string like</p>
  
  <pre><code>const data = "1350, 1351, 1390-1391, 1401, 1402 - 1407";
  </code></pre>
  
  <p>to an array like</p>
  
  <pre><code>const range = [
      {
          min: 1350,
          max: 1350,
      },
      {
          min: 1351,
          max: 1351,
      },
      {
          min: 1390,
          max: 1391,
      },
      {
          min: 1401,
          max: 1401,
      },
      {
          min: 1402,
          max: 1407,
      },
  ];
  </code></pre>
  
  <p>?</p>
  
  <p>In other words, you need to create an array of number ranges using a string in which these numbers ranges are explicitly specified.</p>
  
  <p>The most obvious of the possible algorithms is:</p>
  
  <p>1) split the string using a delimiter<code>,</code></p>
  
  <p>2) the resulting parts are cleaned of spaces using the command <code>trim</code></p>
  
  <p>3) check whether the part is a number</p>
  
  <p>4) if not, then split the part using the delimiter <code>-</code></p>
  
  <p>5) the parts obtained are cleaned of spaces using the command <code>trim</code>,</p>
  
  <p>6) check that the amount of component eq 2 and it's a number</p>
  
  <p>But is it possible to make it more optimal, more beautiful, more effective?</p>