Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, May 13, 2017

FreeCodeCamp Search and Replace Sample Solution



function myReplace(str, before, after) {
  var test = '/'+ before +'/';
  //return after;
  if(before[0] == before[0].toUpperCase()){
    var firstLetter = after.split('').splice(0,1);
    var restOfTheWord = after.split('').splice(1,after.length).join('');
    after = firstLetter[0].toUpperCase()+restOfTheWord;
  }
  var newstr = str.split(before).join(after);
  return newstr;
}

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

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts