JSFiddle - React, Tailwind, and code Playground

by Santosh Giridhara

JavaScript

String.prototype.repeat = function(n) {
  let seed = this;
  let result = "";
  while (n) {
    if (n % 2 == 1) {
      result += seed;
    }
    if (n > 1) {
      seed += seed;
    }
    n >>= 1;
  }
  return result;
}

var str = 'I did not understand the question \n';
console.log(str.repeat(20));