Nodejs String Repeat unrepeat()

Here you can find the source of unrepeat()

Method Source Code

String.prototype.unrepeat = function() {
  var t = String(this)
  // check for 3+ duplicated letters
  while(matches = /(.)\1{2,}/.exec(t)) {
    t = t.replace(matches[0],matches[1])
  }//w  w w.j  a va 2  s  .c o m
  return t;
}

Related

  1. repeatifyString.prototype.repeatify || (times)
    String.prototype.repeatify = String.prototype.repeatify || function(times) {
       var str = '';
       for (var i = 0; i < times; i++) {
          str += this;
       return str;
    };
    console.log('hello'.repeatify(3));
    
  2. repeatifyString.prototype.repeatify || (times)
    String.prototype.repeatify = String.prototype.repeatify || function(times) {
       let str = '';
       for (let i = 0; i < times; i++) {
          str += this;
       return str;
    };
    console.log('hello'.repeatify(3));  
    
  3. repeatrepeat(count)
    String.prototype.repeat = function repeat(count) {
      'use strict';
      if (this === undefined || this === null) {
        throw new TypeError(this + ' is not an object');
      if (count < 0 || count === Infinity) {
        throw new RangeError(count + ' is less than zero or equal to infinity');
      return new Array((parseInt(count, 10) || 0) + 1).join(this);
    ...
    
  4. repeatt(count)
    String.prototype.repeatt = function(count) {
        var newText = "";
        for(var i = 0; i < count; i++) {
            newText += this.toString();
        return newText;
    };
    
  5. repeatt(times)
    String.prototype.repeatt = function(times) {
      var repeated = '';
      for (var i = 0; i < times; i++) {
        repeated = repeated + this;
      return repeated;
    };