Created
July 20, 2015 21:58
-
-
Save alan2207/8faddf90f1735460da2a 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){ | |
if(before.charAt(0).toUpperCase()){ | |
after.split("")[0]=after.charAt(0).toUpperCase() | |
newArr.push(after) | |
} | |
}else{ | |
newArr.push(arr[i]) | |
} | |
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