Skip to content

Instantly share code, notes, and snippets.

@sergiodxa
Last active August 29, 2015 14:06
Show Gist options
  • Save sergiodxa/d2fa84e83b7d41f6fd5a to your computer and use it in GitHub Desktop.
Save sergiodxa/d2fa84e83b7d41f6fd5a to your computer and use it in GitHub Desktop.
Función para capitalizar strings
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