Nodejs String Repeat repeatify(times)

Here you can find the source of repeatify(times)

Method Source Code

/**/*from w  ww  . j a  v a2s  .  c o  m*/
 * JavaScript objects only have one construct, objects. Each object has an internal link to another object called its Prototype. This Prototype object has a Prototype of its own, and so on until an object is reached with a null as its Prototype.
 * - this is called the Prototype chain
 *
 * Extending natice prototypes: this is considered bad practice and breaks encapsulation. The only good reason for extending a built-in prototype is to backport the features of newer JavaScript engines.
 */

String.prototype.repeatify = String.prototype.repeatify || function(times) {
    var string = '';
    for (var i = 0; i < times; i++) {
        string += this;
    }

    return string;
}

console.log('Hello'.repeatify(5));

Related

  1. repeatify(n)
    String.prototype.repeatify = function(n) {
      var str = ''
      for (var i = 0; i < n; i++) {
        str += this
      return str
    console.log('hello'.repeatify(3))
    
  2. repeatify(numTimes)
    String.prototype.repeatify = function(numTimes) {
        var strArray = "";
        for (var i = 0; i < numTimes; i++) {
            strArray += this;
        return strArray;
    };
    console.log('hello'.repeatify(6));
    
  3. 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("Jai Mata Di\n".repeatify(108));
    
  4. 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));
    
  5. repeatify(times)
    'use strict';
    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));
    ...
    
  6. 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));
    
  7. repeatify(times)
    String.prototype.repeatify = String.prototype.repeatify || function(times) {
       var str = '';
       for (var i = 0; i < times; i++) {
          str += this;
       return str;
    };
    
  8. repeatify(timesToRepeat)
    String.prototype.repeatify = function(timesToRepeat) {
       var string = this;
       for (var i = 1; i < timesToRepeat; i++) {
          string += this;
       return string;
    };
    
  9. repeatifyString.prototype.repeatify || (times)
    String.prototype.repeatify = String.prototype.repeatify || function (times) {
      var str = '';
      for (var i = times; i--;) {
        console.log(i);
        str += this;
      return str;
    };
    console.log('1  '.repeatify(6))
    ...