Last active
November 12, 2020 04:56
-
-
Save dinocarl/ad959d7d0edca79aa9521d73d0d47456 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
// use transducers | |
const appendTo = flip(append); | |
const apCh = (fn, accVal) => (item) => accVal = fn(accVal, item); | |
const steps = [ | |
filter(test(/[()]/)), | |
map((item) => item === '(' ? 1 : -1), | |
map(apCh(add, 0)), // scan transducer | |
]; | |
const transformer = compose(...steps); | |
const maxdepth = compose( | |
apply(Math.max), | |
transduce(transformer, appendTo, []), | |
split('') | |
); | |
const s = `(5*(2+(6-3)-(2-(1))))`; | |
maxdepth(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment