Skip to content
Advertisement

How do I write a JavaScript program for the question given below

Write a function that takes three (str, c, n) arguments. Start with the end of ‘str’. Insert character c after every n characters?

JavaScript

I think, I am using wrong method.

Advertisement

Answer

Start with the end of ‘str’. Insert character c after every n characters?

I assumed this means the string needs to end with c after the change. Correct me if I’m wrong.

If that’s the case Array.prototype.reverse() and Array.prototype.map() can help here:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement