你必須很努力

Day23 - Codewars 刷題

2019/10/02
字數統計: 148閱讀時間: 1 min

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

Codewars LV6


題目(CamelCase Method)

1
2
3
4
5
6
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

1
2
3
4
5
6
7
8
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


答案:

1
2
3
4
5
6
# CamelCase Method
class String
def camelcase
self.split.map{ |x| x.capitalize }.join
end
end

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

原文連結:https://riverye.com/2019/10/02/Day23-Codewars-刷題/

發表日期:2019-10-02

更新日期:2019-10-09

CATALOG