Python Algorithm: Jaden Casing Strings
Capitalizing every word in a string
We are going to write a function called to_jaden_case
that will accept a string, string
, as an argument.
To begin with the origin of the function name, I’ll quote the instructions off of the Codewars algorithm page:
Jaden Smith, the son of Will Smith, is the star of films such as The Karate Kid (2010) and After Earth (2013). Jaden is also known for some of his philosophy that he delivers via Twitter. When writing on Twitter, he is known for almost always capitalizing every word.
You are given a string and the goal of the function is to return the string with each word capitalized.
Example:
quote = "How can mirrors be real if our eyes aren't real"# output: "How Can Mirrors Be Real If Our Eyes Aren't Real"
First, we are going to convert the string input into a list by using split()
. We assign the array to textArr
.
textArr = string.split(" ")
We will create another variable called jadenCaseArr
and assign it an empty list. This list will contain every word from string
but capitalized.
jadenCaseArr = []