Skip to content

Commit cfdf3fe

Browse files
committed
Add codewars (6) weird string case
1 parent f36bb7a commit cfdf3fe

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: 0_code_wars/6_weird_string_case.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://www.codewars.com/kata/weird-string-case/
2+
# --- iteration 1 ---
3+
def weirdcase(string)
4+
string.split(" ").map! do |word|
5+
word.chars.map.with_index { |char, idx| idx.even? ? char.upcase : char.downcase }.join
6+
end.join(" ")
7+
end
8+
9+
# --- iteration 2 ---
10+
def weirdcase(string)
11+
string.gsub(/\w{1,2}/, &:capitalize)
12+
end

0 commit comments

Comments
 (0)