Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ok the code is now 100% more better
- const specialchar = (str="Test String", char=" ") => {
- if (typeof str != "string" || typeof char != "string" || char.length > 1) return undefined
- else return str.split("").join(char)
- }
- // example
- // code | expected output
- specialchar() // T e s t S t r i n g
- //
- specialchar("foo") // f o o
- specialchar("bar") // b a r
- specialchar("foobar") // f o o b a r
- //
- specialchar("Test String", "_") // T_e_s_t_ _S_t_r_i_n_g
- specialchar("foo", "_") // f_o_o
- specialchar("bar", "_") // b_a_r
- specialchar("foobar", "_") // f_o_o_b_a_r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement