Skip to content

Instantly share code, notes, and snippets.

@lionelB
Created May 1, 2013 16:57
Show Gist options
  • Save lionelB/5496583 to your computer and use it in GitHub Desktop.
Save lionelB/5496583 to your computer and use it in GitHub Desktop.
Capitalize test uppercase() vs fromCharCode()
function capitalize(str) {
return str.substr(0, 1).toUpperCase() + str.substr(1)
}
function capitalize2(str) {
return str.replace(/^[a-zàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ]/, function(x) {
return x.toUpperCase();
});
}
var s = "àáâãäåçèéêëìíîïðòóôõöùúûüýÿñ".split('')
, S = s.map( function(letter){
var l1 = capitalize(letter)
, l2 = capitalize2(letter);
console.log(letter, l1, l2, l1 === l2);
return letter;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment