freeCodeCamp Challenge Guide: Search and Replace

My quick solution:

function myReplace(str, before, after) {
return str.split(before).join(before[0] == before[0].toUpperCase() ? after.charAt(0).toUpperCase() + after.slice(1): after);
}

myReplace(“He is Sleeping on the couch”, “Sleeping”, “sitting”);

7 Likes