延續昨天的題目繼續解 Codewars LV5 題目,
參考網路大大寫法,以自己的方式說明。
1
2
3
4
5Move 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 !
1
2
3
4
5
6def 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');
影片解題:
答案:
1
2
3
4
5#Simple Pig Latin
def pig_it text
text.gsub(/(\w)(\w+)*/, '\2\1ay')
end
#非正確答案喔!!
下集待續..
本文同步發布於 小菜的 Blog https://riverye.com/