Reverse Characters of a String in Parentheses

inputString= “(foo)”
output should be "oof"
inputString = foo(bar)baz
output should be "foorabbaz
inputString = "foo(bar)baz(blim)"
output should be "foorabbazmilb
inputString = "foo(bar(baz))blim"
output should be "foobazrabblim"
Because "foo(bar(baz))blim" becomes "foo(barzab)blim" and then "foobazrabblim"
stack: [ [ 'f' ] ]
stack: [ [ 'f', 'o' ] ]
stack: [ [ 'f', 'o', 'o' ] ]
stack: [ [ 'f', 'o', 'o' ], [] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b' ] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a' ] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a', 'r' ] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a', 'r' ], [] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a', 'r' ], [ 'b' ] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a', 'r' ], [ 'b', 'a' ] ]
stack: [ [ 'f', 'o', 'o' ], [ 'b', 'a', 'r' ], [ 'b', 'a', 'z' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b', 'b' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b', 'b', 'l' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b', 'b', 'l', 'i' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b', 'b', 'l', 'i', 'm' ] ]
stack: [ [ 'f', 'o', 'o', 'b', 'a', 'z', 'r', 'a', 'b', 'b', 'l', 'i', 'm' ] ]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store