-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path08_my_string.ex
51 lines (41 loc) · 1.02 KB
/
08_my_string.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule MyString do
# def capitalize_words(title) do
# words = String.split(title)
# capitalized_words = Enum.map(words, &String.capitalize/1)
# Enum.join(capitalized_words, " ")
# end
# def capitalize_words(title) do
# Enum.join(
# Enum.map(
# String.split(title),
# &String.capitalize/1
# ),
# " "
# )
# end
# def capitalize_words(title) do
# title
# |> String.split()
# |> Enum.map(&String.capitalize/1)
# |> Enum.join(" ")
# end
def capitalize_words(title) do
title
|> String.split()
|> capitalize_all
|> join_with_whitespace
end
def capitalize_all(words) do
words
|> Enum.map(&String.capitalize/1)
end
def join_with_whitespace(words) do
words
|> Enum.join(" ")
end
end
MyString.capitalize_words("a whole new world") |> IO.inspect()
IO.puts("")
"a whole new world" |> String.split() |> IO.inspect()
IO.puts("")
"a whole new world" |> String.split() |> Enum.map(&String.capitalize/1) |> IO.inspect()