Last active
October 18, 2019 09:51
-
-
Save kmarenov/b25ef76834774da24a0f35e72fa3e305 to your computer and use it in GitHub Desktop.
prefix to infix
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
| function convert(tokens) { | |
| const token = tokens.splice(0, 1)[0]; | |
| if (token === 'NOT') { | |
| return `(${token} ${convert(tokens)})`; | |
| } | |
| if (['AND', 'OR'].includes(token)) { | |
| return `(${convert(tokens)} ${token} ${convert(tokens)})`; | |
| } | |
| return token; | |
| } | |
| const source = "AND OR A B OR C NOT D"; | |
| const tokens = source.split(' '); | |
| console.log(convert(tokens)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment