Javascript String scatter()

Description

Javascript String scatter()





String.prototype.scatter = function() {
    var newString = '';
    for (var i = 0; i < this.length; ++i) {
        var at = this.charAt(i);
        newString += '  ' + at;
    }/* w w w . j a v  a  2 s  .c o  m*/
    return newString;
};

Number.prototype.asScatteredString = function() {
    var asString = '' + this;
    var size = 3 - asString.length;
    return size > 0 ? ' '.repeat(size) + asString : asString;
};

String.prototype.repeat = function(times) {
    times = times || 0;
    if (times < 0) {
        times = 0;
    }
    return new Array(times + 1).join(this);
};



PreviousNext

Related