The Ultimate Guide to JavaScript Algorithms: Search and Replace

Written by Scotch.io - - Aggregated on Friday February 8, 2019

The "Search and Replace" functionality is very common within word processing applications used for creating notes, documents and things of that nature. In this challenge, we implement this functionality in JavaScript in two distinct ways.

Curious already? Let’s see how!

You should already have your development environment setup for this course. Update your cloned repository by running the command git pull. Inside the Beginner folder, navigate to the searchReplace folder. Our work for this challenge will be done in here. Make sure to follow along in the index-START.js file.

The Challenge

Receiving a sentence, a word in the sentence and a replacement for that word as arguments, perform a search and replace on the sentence using the arguments provided and return the new sentence. E.g

searchReplace("He is Sleeping on the couch", "Sleeping", "sitting") 
// should return "He is Sitting on the couch"

Note: Make sure to match the casing(capitalization) of the string to be replaced as shown above.

To the code arena!


« JavaScript Glossary: Array .slice() … - Scotch.io

Scotch.io - The Ultimate Guide to JavaScript … »