Last active
July 23, 2018 10:41
-
-
Save jlogix/41236d0c9a3b20a0e1e54d5505d0f14d to your computer and use it in GitHub Desktop.
This file contains 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
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