Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const replaceAll = (text, char) => {
- if (typeof text != "string" || !text || typeof char != "string" || !char || char.length > 1) return undefined
- else {
- let replaced = ""
- for (let i = 0; i != text.length; i++) {
- replaced += char
- }
- return replaced
- }
- }
- // example
- // code | expected output
- replaceAll("foo", "-") // ---
- replaceAll("bar", "-") // ---
- replaceAll("foobar", "-") // ------
- //
- replaceAll("foo", "*") // ***
- replaceAll("bar", "*") // ***
- replaceAll("foobar", "*") // ******
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement