延續昨天的題目繼續解 Codewars LV5 題目,
參考網路大大寫法,以自己的方式說明。
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
Examples
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !') # elloHay orldway !
def pig_it text
# ...
end
Test.assert_equals(pig_it('Pig latin is cool'),'igPay atinlay siay oolcay')
Test.assert_equals(pig_it('This is my string'),'hisTay siay ymay tringsay');
答案:
#Simple Pig Latin
def pig_it text
text.gsub(/(\w)(\w+)*/, '\2\1ay')
end
#非正確答案喔!!
下集待續..
本文同步發布於 小菜的 Blog https://riverye.com/