Intermediate Algorithm Challenge: Search and Replace : what happened to String.prototype.replaceAt?

Intermediate Algorithm Challenge: Search and Replace : what happened to String.prototype.replaceAt?
0

#1

I used String.prototype.replaceAt to solve the Intermediate Algorithm challenge Search and Replace b/c it was the solution for Beginner Algorithm Title Case a Sentence. Why wasn’t this mentioned in the solution for Intermediate Level Search and Replace?

String.prototype.replaceAt = function(index,character){
    return this.substr(0,index) + character + this.substr(index + character.length);
  };
function myReplace(str,before,after){
  if (before[0] === before[0].toUpperCase()){
    altAfter = after.replaceAt(0, after.charAt(0).toUpperCase());
    return str.replace(before, altAfter);
  }
  return str.replace(before,after);
}
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");

The above code works. I’m just wondering why the solution from a previous challenge wouldn’t be mentioned as possible solution for this challenge. It builds upon what we know.


#2

Probably, because not everyone used String.prototype.replactAt in their Title Case a Sentence solution. I am also not aware that this replaceAt function is mentioned in any of the challenge instructions. Can you post a link where this is the case?


#4

function titleCase(str) {
str = str.toLowerCase();
str = str.split(’ ‘);
var text = str;
var temp = [];
for(var i = 0; i < str.length; i++){
temp[i] = str[i].charAt(0).toUpperCase();
text[i] = text[i].substr(1);
text[i] = temp[i] + text[i];
}
text= text.join(’ ');
return text;
}

titleCase(“I’m a littKLJle tea pot”);