Does anybody know why this function doesn't return the second initial? Expected: 'S.H', instead got: 'S. '
function abbrevName('Sam Hayes'){
let initials = 'x.x';
for (let i = 0; i < name.length; i++) {
if (name[i] === name[i].toUpperCase()) {
initials = initials.replace('x', name[i]);
}
}
return initials;
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment