Created
March 17, 2018 22:07
-
-
Save anonymous/50aaa98b852d23d513e157cd8f3f2c63 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
const origin = '(a,(b,(c,(d,(e,(f))))))' | |
function reorder(str) { | |
let matches = str.match(/^\((\w),(.*)\)$/) | |
if (matches) { | |
const [left, right] = reorder(matches[2]) | |
return [`${left},(${matches[1]}`, `)${right}`] | |
} else { | |
let matches = str.match(/^\((\w)\)$/) | |
return [`(${matches[1]}`, ')'] | |
} | |
} | |
let [left, right] = reorder(origin) | |
console.log(`${left}${right}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment