---
# System prepended metadata

title: 1678. Goal Parser Interpretation

---

# 1678. Goal Parser Interpretation

## 題目概要
將 `"G"` 轉為 `G`，將`()` 轉為 `o`，將`(al)` 轉為 `al`。

```
Example 1:

Input: command = "G()(al)"
Output: "Goal"
Explanation: The Goal Parser interprets the command as follows:
G -> G
() -> o
(al) -> al
The final concatenated result is "Goal".

Example 2:

Input: command = "G()()()()(al)"
Output: "Gooooal"

Example 3:

Input: command = "(al)G(al)()()G"
Output: "alGalooG"
```

## 解題技巧

- 用 while 循環加 replace 解決。

## 程式碼

```javascript=
/**
 * @param {string} command
 * @return {string}
 */
var interpret = function(command) {
    while (command.includes("("))
        command = command.replace("()", "o").replace("(al)", "al")
    return command;
};
```

![](https://i.imgur.com/f4eJm9a.png)
