function myReplace(str, before, after) {
let newArr1 = []
let arr = str.split(" ");
console.log(arr);
let beforeArr = before.split(" ");
console.log(beforeArr);
let register = beforeArr.join("").match(/[A-Z]/);
newArr1.push(register)
console.log(newArr1.length);
let newAfter;
if (newArr1.length > 0){
newAfter = after.charAt(0).toUpperCase() + after.slice(1);
console.log(newAfter);
return newAfter;
}
console.log(newAfter);
for (let i = 0; i < arr.length; i++) {
if (arr[i]== beforeArr){
let num = arr.indexOf(arr[i]);
delete arr[i];
return arr.splice(num , 1 ,after );
}
}
console.log(arr.join(" "));
// return arr.join(" ");
}
myReplace("His name is Tom", "Tom", "john");
Не могу понять почему функция не проходит тесты:
```
myReplace("Let us go to the store", "store", "mall") should return "Let us go to the mall".
myReplace("He is Sleeping on the couch", "Sleeping", "sitting") should return "He is Sitting on the couch".
myReplace("This has a spellngi error", "spellngi", "spelling") should return "This has a spelling error".
myReplace("His name is Tom", "Tom", "john") should return "His name is John".
myReplace("Let us get back to more Coding", "Coding", "algorithms") should return "Let us get back to more Algorithms".
```
link :
https://learn.freecodecamp.org/javascript-algorith...
Спасибо за помощь