Last active
October 11, 2019 13:10
-
-
Save ourmaninamsterdam/d5cb3d2ad91d1022c01cfe05c43db914 to your computer and use it in GitHub Desktop.
Split string, flatten and convert ranges to array of numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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