Last active
November 22, 2015 04:01
-
-
Save minsooshin/13e0b293561de7920aed to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Search and Replace
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
// Bonfire: Search and Replace | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-search-and-replace | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function myReplace(str, before, after) { | |
if ((/^[A-Z]/).test(before)) after = after.charAt(0).toUpperCase() + after.slice(1); | |
str = str.replace(new RegExp(before, 'gi'), after); | |
return str; | |
} | |
myReplace("He is Sleeping on the couch", "Sleeping", "sitting"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment