I need a function that removes all instances of a specific substring from a string, except for the first one. For example:
function keepFirst(str, substr) { ... }
keepFirst("This $ is some text $.", "$");
The expected result should be: This $ is some text .
I could achieve this by using split()
followed by a for(){}
loop, but I'm wondering if there's a more elegant solution available.