Nodejs String Repeat repeatify(times)

Here you can find the source of repeatify(times)

Method Source Code

// Basic alert//from  ww  w  . j  a va2s . c  o m
// console.log("hello from Me");


// Write something to web page
// document.write("Hello Boulder");


// Variables
// var nameList = 100;
//
//   console.log(nameList);

// Arrays
// var arrayName = new Array(10, 20, 40, 4000, 200, "Dude!");
//
// console.log(arrayName[3]);
// console.log(arrayName[1]);
// console.log(arrayName[0]);
// console.log(arrayName[5]);

// Define a repeatify function on the String object. The function accepts an integer
// that specifies how many times the string has to be repeated. The function returns
// the string repeated the number of times specified. For example: console.log('hello'.repeatify(3));

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));

Related

  1. 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));
    
  2. 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));
    
  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('hello'.repeatify(3));
    
  4. 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));
    ...
    
  5. repeatify(times)
    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));
    
  6. repeatify(times)
    String.prototype.repeatify = String.prototype.repeatify || function(times) {
       var str = '';
       for (var i = 0; i < times; i++) {
          str += this;
       return str;
    };
    
  7. repeatify(timesToRepeat)
    String.prototype.repeatify = function(timesToRepeat) {
       var string = this;
       for (var i = 1; i < timesToRepeat; i++) {
          string += this;
       return string;
    };
    
  8. 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))
    ...
    
  9. repeatifyString.prototype.repeatify || (num)
    String.prototype.repeatify = String.prototype.repeatify || function(num){
      "use strict";
      let newString = "";
      while(num >0){
        newString +=this;
        num--;
      return newString;
    };
    ...