Skip to content

Instantly share code, notes, and snippets.

@alan2207
Created July 20, 2015 17:44
Show Gist options
  • Save alan2207/19cf01f9cfe85dadfb53 to your computer and use it in GitHub Desktop.
Save alan2207/19cf01f9cfe85dadfb53 to your computer and use it in GitHub Desktop.
function replace(str, before, after) {
var arr = str.split("")
var newArr = []
for(i=0;i<arr.length;i++){
if (arr[i]!=before){
newArr.push(arr[i])
}else{
newArr.push(after)
}
var newStr = newArr.join("")
}
return newStr
}
replace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment