Answers for "repeat string n times javascript"

2

repeat string n times javascript

"a".repeat(10)
Posted by: Guest on March-28-2021
2

js string times

let string = 'Plumbus'
let count = 3

string.repeat(count); // -> 'PlumbusPlumbusPlumbus'
Posted by: Guest on May-17-2020
5

JavaScript repeat character

var a="a";
var aaa=a.repeat(3); // "aaa"
Posted by: Guest on July-31-2019
2

how to return a string x amount in javascript without using . repeat

function repeatStringNumTimes(string, times) {
  var repeatedString = "";
  while (times > 0) {
    repeatedString += string;
    times--;
  }
  return repeatedString;
}
repeatStringNumTimes("abc", 3);
Posted by: Guest on June-10-2020
0

repeat x times js

The code below is written using ES6 syntaxes but could just as easily be written in ES5 or even less. ES6 is not a requirement to create a "mechanism to loop x times"

If you don't need the iterator in the callback, this is the most simple implementation

const times = x => f => {
  if (x > 0) {
    f()
    times (x - 1) (f)
  }
}

// use it
times (3) (() => console.log('hi'))

// or define intermediate functions for reuse
let twice = times (2)

// twice the power !
twice (() => console.log('double vision'))
Posted by: Guest on March-18-2021

Code answers related to "repeat string n times javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language