Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Last active October 11, 2019 13:10
Show Gist options
  • Save ourmaninamsterdam/d5cb3d2ad91d1022c01cfe05c43db914 to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/d5cb3d2ad91d1022c01cfe05c43db914 to your computer and use it in GitHub Desktop.
Split string, flatten and convert ranges to array of numbers
"1,40-44"
.split(',')
.map(item => item.trim().split('-')
.map(item => parseInt(item.trim()))) // [[1], [40,44]]
"2-3,10,12,45,46-59"
.split(',')
.map(item => item.trim().split('-')
.map(item => parseInt(item.trim()))) // [[2,3], [10,12,45], [46,59]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment