Pig Latin

Translate the provided string to pig latin.

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”.

If a word begins with a vowel you just add “way” to the end.

Input strings are guaranteed to be English words in all lowercase.

输入一个字符串,如果首字母为辅音,移到尾部,加后缀ay,如果为元音’aeiou’,加后缀way


function translatePigLatin(str) {
  var arr = str.split('');
  var reg = 'aeiou';
  if (reg.indexOf(arr[0]) !== -1) {
    arr.push('way');
    return arr.join('');
  } else {
    for (var i = 0; i<arr.length; i++) {
      if (reg.indexOf(arr[0]) === -1) {
        var first = arr.shift();
        arr.push(first);
      } else {
        arr.push('ay');
        return arr.join('');
      }
    }
  }

}

translatePigLatin("consonant");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值