Created
January 19, 2018 15:10
-
-
Save screeny05/e2c65fc85867babc54126f6d5635477f to your computer and use it in GitHub Desktop.
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
const parsePagination = s => | |
s | |
.split(',') | |
.map(s => { | |
if(s.match(/^\d+$/)){ | |
return parseInt(s); | |
} | |
if(s.match(/^\d+-\d+$/)){ | |
s = s.split('-'); | |
return Array(s[1] - s[0] + 1) | |
.fill(0) | |
.map((v, i) => i + parseInt(s[0])); | |
} | |
throw new SyntaxError('Cannot parse string ' + s); | |
}) | |
.reduce((acc, v) => acc.concat(v), []); |
Author
screeny05
commented
Jan 19, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment