Skip to content

Instantly share code, notes, and snippets.

@jlogix
Last active July 23, 2018 10:41
Show Gist options
  • Save jlogix/41236d0c9a3b20a0e1e54d5505d0f14d to your computer and use it in GitHub Desktop.
Save jlogix/41236d0c9a3b20a0e1e54d5505d0f14d to your computer and use it in GitHub Desktop.
var lines = layout.split(/[\r\n]/) // split layout into individual lines
.map(
i=>i.match(/\+/)? // '+' means one or more boxes ending
i.split(/[\+\|]/)
.filter(e=>e) // filter out zero length lines
.map(
b=>b.match(/^\-+$/)? // all '-'s mean box is ending here
-(b.length+1): // denote that by -ve number
b.length+1) // box still open. put +ve length
:i.split(/\|/) // if '+' not found, then split at '|'
.filter(e=>e) // filter out zero length lines
.map(b=>b.length+1)) // put box width in the array
.filter(e=>e.length); // filter out empty arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment