Last active
August 29, 2015 14:06
-
-
Save sergiodxa/d2fa84e83b7d41f6fd5a to your computer and use it in GitHub Desktop.
Función para capitalizar strings
This file contains 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
function capitalize() { | |
try { | |
if (typeof this !== 'string') throw new Error('Capitalize must be used in a String value.'); | |
const str = this.split(' ') | |
.map(v => { | |
return v.split('') | |
.map((v,i) => (i === 0) ? v.toUpperCase() : v) | |
.join(''); | |
}).join(' '); | |
return str; | |
} catch (error) { | |
return error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment