Skip to content

Instantly share code, notes, and snippets.

@mgroves
Last active September 15, 2015 21:14
Show Gist options
  • Select an option

  • Save mgroves/d40f18b608ea93b049bb to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/d40f18b608ea93b049bb to your computer and use it in GitHub Desktop.
function replaceASingleCharacter(str, singleCharacter, replaceWith) {
// put regex replace here
// something like return str.replace(/blahblahregex/,replaceWith);
}
var result1 = replaceASingleCharacter("This X should be replaced","X","Y");
if(result1 != "This Y should be replaced") {
console.log("fail 1");
}
var result2 = replaceASingleCharacter("These XX should NOT be replaced","X","Y");
if(result2 != "These XX should NOT be replaced") {
console.log("fail 2");
}
var result3 = replaceASingleCharacter("This X should be replaced, but the XX should not be","X","Y");
if(result3 != "This Y should be replaced, but the XX should not be") {
console.log("fail 3");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment