iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 26
0
自我挑戰組

自我挑戰 Ruby 刷題 30 天系列 第 26

Day26 - Codewars 刷題

延續昨天的題目繼續解 Codewars LV5 題目,
參考網路大大寫法,以自己的方式說明。


題目(Simple Pig Latin)

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');

影片解題:
Yes


答案:

#Simple Pig Latin
def pig_it text
  text.gsub(/(\w)(\w+)*/, '\2\1ay')
end
#非正確答案喔!!

下集待續..

本文同步發布於 小菜的 Blog https://riverye.com/


上一篇
Day25 - Codewars 刷題
下一篇
Day27 - Codewars 刷題
系列文
自我挑戰 Ruby 刷題 30 天31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言