zoukankan      html  css  js  c++  java
  • JavaScript 'Pig latin is cool'==>'igPay atinlay siay oolcay'

    Description:

    Move the first letter of each word to the end of it, then add 'ay' to the end of the word.

    console.log(pigIt('Pig latin is cool')); // igPay atinlay siay oolcay
    
    • my answer:使用正则
    function pigIt(str){
      return str.replace(/(w)(w*)(s|$)/g, "$2$1ay$3")
    }
    
    function pigIt(str){
      return str.replace(/(w)(w+)/ig,"$2$1ay");
    }
    
    • other answer:
    function pigIt(str){
      return str.split(' ').map(function(el){
        return el.slice(1) + el.slice(0,1) + 'ay';
      }).join(' ');
    }
    
  • 相关阅读:
    DevOps
    DevOps
    DevOps 教程
    Java 文件
    Java 包装类
    Java HashMap
    Java 包装类
    Java 文件
    Java ArrayList
    Java 日期与时间
  • 原文地址:https://www.cnblogs.com/kid2333/p/7466589.html
Copyright © 2011-2022 走看看