I finished this Algorithm for a longtime but now i come back to change a solution by using Functional Programming - Higher Order Function for practice myself to learning React and rxjs . So my question is can i change this solution to the currying function ? And my solution is closure or not ?
const myReplace = str => before => after => {
const CheckUpperCase = (before,after) => {
if(before[0] === before[0].toUpperCase()){
after = after.split("");
after[0] = after[0].toUpperCase();
after = after.join("");
return after;
}else{
return after;
}
};
let a = str.split(' ');
let left = a.splice(0,a.indexOf(before));
let right = a.splice(a.indexOf(before)+1,a.length);
const result = (spliceLeft,spliceRight,checkCharacterCase) => {
return spliceLeft.concat(checkCharacterCase(before,after),spliceRight).join(" ");
};
return result(left,right,CheckUpperCase);
};
myReplace("He is Sleeping on the couch")("Sleeping")("sitting");