← Back to challenges

Censor Words from Array

JavaScriptHardstringslanguage_fundamentalsformatting

Instructions

Create a function that takes a string str and censors any word from a given array arr. The text removed must be replaced by the given character char.

Examples

censorString("Today is a Wednesday!", ["Today", "a"], "-") ➞ "----- is - Wednesday!"

censorString("The cow jumped over the moon.", ["cow", "over"], "*"), "The *** jumped **** the moon.")

censorString("Why did the chicken cross the road?", ["Did", "chicken", "road"], "*") ➞ "Why *** the ******* cross the ****?"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.