Created
December 11, 2015 03:34
-
-
Save anonymous/d3788626101e338d1f47 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Search and Replace
This file contains hidden or 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: @tylerl-uxai | |
// 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) { | |
var i = str.indexOf(before); | |
if (str[i] == str[i].toUpperCase()){ | |
after = after.charAt(0).toUpperCase() + after.slice(1); | |
} | |
return str.replace(before, after); | |
} | |
myReplace("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