Created
July 20, 2015 17:44
-
-
Save alan2207/19cf01f9cfe85dadfb53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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