Forked from anonymous/bonfire-search-and-replace.js
Created
December 11, 2015 03:34
-
-
Save TylerL-uxai/27d55cb90a90d2777b4d 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) | |
// Rewritten by myself with the help of https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Bonfire-Search-and-Replace | |
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