Here you can find the source of upWord()
// Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in upper case // Example string : 'the quick brown fox' // Expected Output : 'The Quick Brown Fox ' String.prototype.upWord = function (){ var words = this.split(" "); var newWords = words.map(function(elem,index) { return (elem[0].toUpperCase() + elem.slice(1)); })/* w ww . j a va 2 s.c o m*/ return newWords.join(" "); } var str = "the quick fox jump over the lazy dog"; console.log(str.upWord());
String.prototype.ucwords = function() { return (this + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) { return $1.toUpperCase(); });
String.prototype.ucwords = function () { var words = this.split(' '); for (var i = 0; i < words.length; i++) words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1); return words.join(' '); }; module.exports = function () { };
String.prototype.ucwords = function(){ var arr = this.split(' '); var str =''; arr.forEach(function(v){ str += v.charAt(0).toUpperCase()+v.slice(1,v.length)+' '; }); return str; };
String.prototype.ucwords = function(){ return this.replace(/(?:^|\s)\S/g,function(v){return v.toUpperCase();}); };
String.prototype.ucwords = function () { return this.toLowerCase().replace(/^.|\s\S/g, function (a) { return a.toUpperCase(); }); };
String.prototype.upcase = function () { return this.valueOf().toUpperCase(); };
String.prototype.upcase = function(){ return this.toUpperCase(); };
String.prototype.upperCaseFirst = function() { return this.replace(/^./, function(a) { return a.toUpperCase(); }); };
String.prototype.upperFirstChar = function() { return this.charAt(0).toUpperCase() + this.slice(1)