Intermediate Algorithm Scripting: Search and Replace, required help?

Tell us what’s happening:

all tests are clear except below one;
myReplace("I think we should look up there", "up", "Down") should return “I think we should look down there”.)

Your code so far


function myReplace(str, before, after) {
let strcollection = str.split(" ");

function capitalword(word){
  return word[0] === word[0].toUpperCase();
}
function capitalizeword(word){
  return word[0].toUpperCase() + word.slice(1);
}

return strcollection.map(eachword => {
  if(eachword === before){
    if(capitalword(eachword)){
      after = capitalizeword(after);
    };
    return after;
  }
  return eachword;
}).join(" ");

};

let result = myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36.

Challenge: Search and Replace

Link to the challenge:

You are capitalizing the the first letter if it needs it but you are not lowering the case when it needs to be lowered.