Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2014年12月16日 D5 #27

Open
nunnly opened this issue Dec 16, 2014 · 3 comments
Open

2014年12月16日 D5 #27

nunnly opened this issue Dec 16, 2014 · 3 comments
Labels

Comments

@nunnly
Copy link
Owner

nunnly commented Dec 16, 2014

每个首字母位移到单词末位,然后在每个单词末尾添上ay
PS:只能添加一行代码

function pigIt(str){
  //Code here
}
pigIt('Pig latin is cool'); //igPay atinlay siay oolcay
@think2011
Copy link
Collaborator

啊,看错题目了,首字母移到末位,然后添加ay。
改正后:

function pigIt(str){
    return str.split(' ').map(function(v){return v.slice(1).split('').join('') + v[0] + 'py' }).join(' ');
}

// 测试用例
console.log(pigIt('Pig latin is cool')); //igPay atinlay siay oolcay

@XadillaX
Copy link
Collaborator

function pigIt(str) {
    return str.split(" ").map(function(v) {
        return v.trim().substr(1) + v.trim()[0] + "ay";
    }).join(" ");
}

console.log(pigIt('Pig latin is cool')); //igPay atinlay siay oolcay

@singone
Copy link

singone commented Dec 17, 2014

 function pigIt(str){
        return str.trim().replace(/\S{1,}/g,function(w){return [w.substr(1), w.substr(0,1),'ay'].join('')})
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants