Created
October 27, 2015 15:10
-
-
Save guumaster/1949343af406129489a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let convert = (str) => { | |
return str | |
.trim() | |
.split(/ +/) | |
.reduce((acc, word) => { | |
return (acc + ' ' + word[0].toUpperCase() + word.slice(1).toLowerCase()).trim(); | |
}, ''); | |
} | |
module.exports = convert; |
function capitalizar(){
let frase="hola mundo";
let palabras=frase.split(" ");
let fraseFinal="";
palabras.forEach(function(element, index, array) {
fraseFinal+=" "+element.slice(0, 1).toUpperCase()+element.slice(1);
});
console.log(fraseFinal);
}
'use strict';
let capitalize = function(str){
let words = str.split(' ');
capitalize = words.reduce(function(prev, actual){
var cap = actual[0].toUpperCase();
return prev + ' ' + cap + actual.slice(1) ;
}, '');
return capitalize.trim();
};
module.exports = capitalize;
function capitalizeWord(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
module.exports = {capitalizeWord};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'use strict'
function capitalize(str){
let sRet = "";
let aux = str.split(' ');
for(let i=0;i<aux.length;i++){
sRet += aux[i].charAt(0).toUpperCase() + aux[i].slice(1) + " ";
}
sRet.slice(0, sRet.length-1);
return sRet;
}
module.exports = {
capitalize: capitalize
}