Advertisement
PortalPlayer

turn all text to another char function

Apr 27th, 2020
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const replaceAll = (text, char) => {
  2.     if (typeof text != "string" || !text || typeof char != "string" || !char || char.length > 1) return undefined
  3.     else {
  4.         let replaced = ""
  5.         for (let i = 0; i != text.length; i++) {
  6.             replaced += char
  7.         }
  8.         return replaced
  9.     }  
  10. }
  11.  
  12.  
  13. // example
  14. // code | expected output
  15.  
  16. replaceAll("foo", "-")    // ---
  17. replaceAll("bar", "-")    // ---
  18. replaceAll("foobar", "-") // ------
  19.                           //
  20. replaceAll("foo", "*")    // ***
  21. replaceAll("bar", "*")    // ***
  22. replaceAll("foobar", "*") // ******
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement