JSFiddle - React, Tailwind, and code Playground

JavaScript

function times(str, n){
    var step = str;
    for (var y = 1; y < n; y++){
       str = str.concat(step);
    }
    return str;
}
strings = ["a b c", "a  b c", "1 2 3   34"];

var s;
for (i in strings){
    s = strings[i].replace(/\s{2,}/g, function(match) {
        return times(".", match.length);
    });
    alert(strings[i] + " -> " + s);
}