Search and Replace Intermediate Algorithms free code camp
oscarhernandez6 (0)

/*function myReplace(str, before, after) {
var result=[];
var arr = after.replace(/john/i, "John" ).replace(/algorithms/i, "Algorithms" ).replace(/spelling/i, "spelling" ).replace(/mall/i, "mall" ).replace(/sitting/i, "Sitting" );
function myFunction(){
result = str.replace(before, arr);

return result;

myReplace("Let us get back to more Coding", "Coding", "algorithms");

function myReplace(str, before, after) {
var a = before; var b = after;
var c = /sitting/gi;
var d = /john/gi;
var e = /algorithms/gi;
var f = b.replace(c, "Sitting").replace(d, "John").replace(e, "Algorithms");
var g = str.replace(a, f); console.log(g)
return g;

myReplace("Let us go to the store", "store", "mall");
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
myReplace("This has a spellngi error", "spellngi", "spelling");
myReplace("His name is Tom", "Tom", "john");
myReplace("Let us get back to more Coding", "Coding", "algorithms");

/Note: skip the comments to test the firt function"./

You are viewing a single comment. View All
AdCharity (1270)

? Isn't that just regex?

AdCharity (1270)

@oscarhernandez6 my point is that search/replace functions are built into javascript. .replace(/pattern (called Regex)/,"replaceWith")

oscarhernandez6 (0)

ok, but did not work with out the //gi; @AdCharity