昨天 (正確來說是今天凌晨) 趕專案到 3 點多
還能一早錄影鐵人賽覺得活著真好 xd
Codewars LV6
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')
答案:
# CamelCase Method
class String
def camelcase
self.split.map{ |x| x.capitalize }.join
end
end
本文同步發布於 小菜的 Blog https://riverye.com/