Search and replace challenge issue

Tell us what’s happening:
Could anyone help me figure out where I went wrong here? I’ve been rereading and adjusting it for a few days now. however, I cannot seem to figure out where I went wrong. According to the hint page, it should be correct.

   **Your code so far**

function myReplace(str, before, after) {
 const myArr = str.split(" ");
const [wordToReplace] = myArr.filter(item => item === before);
 return wordToReplace[0].toUpperCase() !== wordToReplace[0]
 ? myArr.map(item => (item === before ? after : item)).join(" ")
 : myArr
 .map(item => 
 item === before ? after[0].toUpperCase() + after.slice(1) : item
 )
 .join(" ");
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
   **Your browser information:**

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

Challenge: Search and Replace

Link to the challenge:

console.log(myReplace("I think we should look up there", "up", "Down"));

It looks like you don’t correctly handle the case where you need to change the capitalization of the replacement word.