I am wondering if anyone knows how to replace n number of occurrences of exclamation marks in a string. I need to remove n exclamation marks in the sentence from left to right and n is always positive integer.
An example would be as follows:
remove("Hi!!!",1) === "Hi!!"
remove("!!!Hi !!hi!!! !hi",3) === "Hi !!hi!!! !hi"
I have tried many approaches but have had no luck so far. Here is my latest attempt.
function remove(str, n){
str.replace(/!{n}/g, '');
}