Hello, this is my first post so bear with me & if this is wrong section then pls move it to the right one. Can any one let me know why the below two blocks of code outputting different strings. I mean the logic is same, they are written in different way(the first one is more shorter form than the second one).
function titleCase(str) {
var strArray = str.split(' ');
var cStrArray = strArray.map(function(val){
return (val.toLowerCase().replace(val[0],val[0].toUpperCase()));
});
return cStrArray.join(' ');
}
titleCase("I'm Nothing");
Which outputs “i’m Nothing”. (sentence starts with lower case ‘i’).
function titleCase(str) {
var strArray = str.split(' ');
var cStrArray = strArray.map(function(val){
val = val.toLowerCase();
return val.replace(val[0],val[0].toUpperCase());
});
return cStrArray.join(' ');
}
titleCase("I'm Nothing");
Which is outputting “I’m Nothing”. (sentence starts with upper case ‘i’).