Last active
February 15, 2019 11:41
-
-
Save florestankorp/e95b5038e4ffadf8a001ad5a97affec5 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 myReplace(str, before, after) { | |
let index = str.indexOf(before); | |
if (str[index] === str[index].toUpperCase()) { | |
after = `${after[0].toUpperCase()}${after.slice(1)}`; | |
} | |
return str.replace(before, after) | |
} | |
let call = myReplace("He is Sleeping on the couch", "Sleeping", "sitting") | |
console.log(call); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment