Pig Latin Translator - JavaScript

后端 未结 10 1785
别跟我提以往
别跟我提以往 2020-12-07 04:09

So for my cit class I have to write a pig Latin converter program and I\'m really confused on how to use arrays and strings together. The rules for the conversion are simpl

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 05:05

    function translate(str) {
         str=str.toLowerCase();
         var n =str.search(/[aeiuo]/);
         switch (n){
           case 0: str = str+"way"; break;
           case -1: str = str+"ay"; break;
           default :
             //str= str.substr(n)+str.substr(0,n)+"ay";
             str=str.replace(/([^aeiou]*)([aeiou])(\w+)/, "$2$3$1ay");
           break;
        }
        return str;
    
    }
    
    
     translate("paragraphs")
    

提交回复
热议问题