Advertisement
PortalPlayer

Character between every char (ignores pre-existing spaces)

Mar 2nd, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ok the code is now 100% more better
  2.  
  3. const specialchar = (str="Test String", char=" ") => {
  4.     if (typeof str != "string" || typeof char != "string" || char.length > 1) return undefined
  5.     else return str.split("").join(char)
  6. }
  7.  
  8. // example
  9. // code | expected output
  10.  
  11. specialchar()                   // T e s t   S t r i n g
  12.                                 //
  13. specialchar("foo")              // f o o
  14. specialchar("bar")              // b a r
  15. specialchar("foobar")           // f o o b a r
  16.                                 //
  17. specialchar("Test String", "_") // T_e_s_t_ _S_t_r_i_n_g
  18. specialchar("foo", "_")         // f_o_o
  19. specialchar("bar", "_")         // b_a_r
  20. specialchar("foobar", "_")      // f_o_o_b_a_r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement