Repeat String - Javascript
javascript, string
Solution
Good news! `String.prototype.repeat` is now a part of JavaScript.
"yo".repeat(2);
// returns: "yoyo"
The method is supported by all major browsers, except Internet Explorer. For an up to date list, see MDN: String.prototype.repeat > Browser compatibility.
MDN has a polyfill for browsers without support.
Problem
What is the best or most concise method for returning a string repeated an arbitrary amount of times? The following is my best shot so far: ``` function repeat(s, n){ var a = []; while(a.length < n){ a.push(s); } return a.join(''); } ```