1678. Goal Parser Interpretation leetcode javascript

1678. Goal Parser Interpretation leetcode javascript

인자인 command는 string형태로주어지며 string의 패턴은 G / () / (al) 셋, 주어진 패턴을 각각 G는 G ()는 o (al)은 al로 바꿔주기만하면되는 문제.  for문과 if문만으로도 처리


/**
 * @param {string} command
 * @return {string}
 */
var interpret = function(command) {
    let answer = ''
    for(i=0;i<command.length ; i++) {
        if(command[i] == "(" && command[i+1] == ")") {
            answer += "o"
        }
        else if(command[i] == "(" && command[i+1] == "a") {
            answer += "al"
        }
        else if(command[i] == "G") {
            answer += "G"
        }
    }
    return answer
};
 

var interpret = function(command) {
    return command.split("()").join("o").split("(al)").join("al");
};