Given a string
\'1.2.3.4.5\'
I would like to get this output
\'1.2345\'
(In case there are no dots in the
Here is another approach:
function process(input) { var n = 0; return input.replace(/\./g, function() { return n++ > 0 ? '' : '.'; }); }
But one could say that this is based on side effects and therefore not really elegant.