If you missed the introductory post, it's here. For a list of previously solved katas, please refer to the bottom of this page.
If this is your first time seeing my post, please note - these katas are probably randomly assigned per user so please don't go into Codewars thinking we will have exactly the same user experience, I am just posting these in the order that I got them.
Kata #21
DESCRIPTION:
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. For simplicity, you'll have to capitalize each word, check out how contractions are expected to be in the example below.
Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes from Jaden Smith, but they are not capitalized in the same way he originally typed them.
Example:
Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real"
Link to Jaden's former Twitter account @officialjaden via archive.org
Starting code:
String.prototype.toJadenCase = function () {
//...
};
My attempt that worked:
String.prototype.toJadenCase = function(tweet) {
let tweetToArr = this.split(' ')
let result = ''
let pos = 1
// if(tweetToArr.length % 2 === 0){
for (w = 0; w < tweetToArr.length && pos < tweetToArr.length; w++){
tweetToArr.splice(pos,0," ")
pos += 2
}
// }
for (i = 0; i < tweetToArr.length; i++){
result += tweetToArr[i][0].toUpperCase()
for(ii = 1; ii < tweetToArr[i].length; ii++){
result += tweetToArr[i][ii].toLowerCase()
}
}
return result
};
What a mind-melting problem. Absolutely got Jaden'd. First time to encounter adding methods to the built-in String prototype which so many resources are saying a "no-no" which took time because I had to figure out that I needed to use the 'this' keyword.

Without a doubt a "D'OH!" moment because I knew I needed the .split() and the .map() methods but didn't know what and how to follow through. Good thing rank #1 in 'Best Practice' shows us how:
String.prototype.toJadenCase = function () {
return this.split(" ").map(function(word){
return word.charAt(0).toUpperCase() + word.slice(1);
}).join(" ");
}
Rank #2 with what I think is RegEx, which is way far ahead for me at this point:
String.prototype.toJadenCase = function () {
return this.replace(/(^|\s)[a-z]/g, function(x){ return x.toUpperCase(); });
};
Rank #3 with what looks like a variation of rank #1:
String.prototype.toJadenCase = function() {
return this.split(' ').map(item => item[0].toUpperCase() + item.slice(1)).join(' ')
};
Rank #4:
String.prototype.toJadenCase = function () {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
return this.split(' ').map(capitalizeFirstLetter).join(' ');
};
Rank #5:
String.prototype.toJadenCase = function () {
return this.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
};
Rank #6:
String.prototype.toJadenCase = function () {
var words = this.split(' ');
for(var i = 0, wordsLen = words.length; i < wordsLen; i++) {
words[i] = words[i][0].toUpperCase() + words[i].slice(1);
}
return words.join(' ');
};
Rank #7:
String.prototype.toJadenCase = function () {
var x = '';
x += this[0].toUpperCase();
for (var i = 1; i < this.length; i++) {
if (this.charAt(i) == " ") {
x += (this[i] + this[i + 1].toUpperCase());
i++; // Increment i to stop the function concatenating the first letter of a new word twice
} else {
x += this[i];
}
}
return x;
};
Showing up to rank #7 because it's the longest code in the top ten approaches and yet it's loads better than mine. Goes to show how stupid and probably buggy my approach was. 🤣 Oh well. ¯\_(ツ)_/¯ Still a beginner, still got loads to learn.
That's it for Kata #21, stay tuned for more katas to be solved!
Link to Kata #1: Square(n) Sum
Link to Kata #2: Convert a Number to a String
Link to Kata #3: DNA to RNA Conversion
Link to Kata #4: Remove First and Last Character
Link to Kata #5: MakeUpperCase
Link to Kata #6: Total amount of points
Link to Kata #7: A Needle in the Haystack
Link to Kata #8: Sum of positive
Link to Kata #9: Basic Mathematical Operations
Link to Kata #10: Beginner - Reduce but Grow
Link to Kata #11: Square Every Digit
Link to Kata #12: Friend or Foe?
Link to Kata #13: Grasshopper - Summation
Link to Kata #14: Get the Middle Character
Link to Kata #15: Descending Order
Link to Kata #16: String ends with?
Link to Kata #17: Sum of two lowest positive integers
Link to Kata #18: Sum of odd numbers