String Case Conversion Algorithms

var console = window.console;
function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0, len=splitStr.length|0; i < len; i=i+1|0) {
// You do not need to check if i is larger than splitStr length, as your for does that for you
// Assign it back to the array
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1).toLowerCase();
}
// Directly return the joined string
return splitStr.join(' ');
}

for (var i=0; i<256; i=i+1|0) {
console.assert( titleCase("I'm a little tea pot") );
}
var console = window.console;
function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}

for (var i=0; i<256; i=i+1|0) {
console.assert( camelize("I'm a little tea pot") );
}
var console = window.console;
function camalize(str) {
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}

for (var i=0; i<256; i=i+1|0) {
console.assert( camalize("I'm a little tea pot") );
}
var console = window.console;
function toCamelCase(string) {
return ("" + string)
.replace(/[-_]+/g, ' ')
.replace(/[^\w\s]/g, '')
.replace(
/\s+(.)(\w+)/g,
($1, $2, $3) => "" + $2.toUpperCase() + $3.toLowerCase()
)
.replace(/\s/g, '')
.replace(/\w/g, s => s.toLowerCase());
}

for (var i=0; i<256; i=i+1|0) {
console.assert( toCamelCase("I'm a little tea pot") );
}
// Only works for Latin-I strings
var console = window.console;
var fromCharCode = String.fromCharCode;
var firstLetterOfWordRegExp = /\b[a-z]|['_][a-z]|\B[A-Z]/g;
function toLatin1UpperCase(x){ // avoid frequent anonymous inline functions
var charCode = x.charCodeAt(0);
return charCode===39 ? x : fromCharCode(charCode^32);
}
function titleCase(string){
return string.replace(firstLetterOfWordRegExp, toLatin1UpperCase);
}

for (var i=0; i<256; i=i+1|0) {
console.assert( titleCase("I'm a little tea pot") );
}
let cap = (str) => {
let arr = str.split(' ');
arr.forEach(function (item, index) {
arr[index] = item.replace(item[0], item[0].toUpperCase());
});

return arr.join(' ');
};
console.log(cap("I'm a little tea pot"));
result
Title Case Transformation using for-loop
0%
Camel Case Transformation using Regular Expressions
0%
Camel Case Transformation using Advanced Regular Expressions
0%
Camel Case Transformation with Extensive Regular Expression Manipulations
0%
Fastest Solution For Latin-I Characters
0%
code block 6
0%