iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 23
0
自我挑戰組

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

Day23 - Codewars 刷題

  • 分享至 

  • xImage
  •  

昨天 (正確來說是今天凌晨) 趕專案到 3 點多
還能一早錄影鐵人賽覺得活著真好 xd

Codewars LV6


題目(CamelCase Method)

Write simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. All words must have their first letter capitalized without spaces.

For instance:

'hello case'.camelcase => HelloCase
'camel case word'.camelcase => CamelCaseWord
class String
  #your cool code here...
end

Test.assert_equals('test case'.camelcase, 'TestCase')
Test.assert_equals('camel case method'.camelcase, 'CamelCaseMethod')
Test.assert_equals('say hello '.camelcase, 'SayHello')
Test.assert_equals(' camel case word'.camelcase, 'CamelCaseWord')

影片解題:
Yes


答案:

# CamelCase Method
class String
  def camelcase
    self.split.map{ |x| x.capitalize }.join
  end
end

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


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

尚未有邦友留言

立即登入留言