fork(1) download
  1. function f (s) {
  2. const nums = [];
  3. s.replace(/(\d+)-(\d+)|(\d+)/g, function(_, $1, $2, $3) {
  4. if ($3)
  5. nums.push(parseInt($3));
  6. else {
  7. for (let a = parseInt($1), b = parseInt($2); a <= b; a++)
  8. nums.push(a);
  9. }
  10. });
  11. return nums;
  12. }
  13.  
  14. print(f(">>1"));
  15. print(f(">>1-3"));
  16. print(f(">>1,3"));
  17. print(f(">>1-3,5,9-10"));
  18.  
Success #stdin #stdout 0.02s 171456KB
stdin
Standard input is empty
stdout
1
1,2,3
1,3
1,2,3,5,9,10