title: Idiom for "repeat n times"?
body: <p>Here's a somewhat wasteful and impractical way to produce an array of 3 random numbers in JS:</p>
  <pre><code>[1, 1, 1].map(Math.random) // Outputs: [0.63244645928, 0.59692098067, 0.73627558014]
  </code></pre>
  <p>The use of a dummy array (e.g. <code>[1, 1, 1]</code>), just so that one can call <code>map</code> on it, is -- for sufficiently large <em>n</em> -- both wasteful (of memory) and impractical.</p>
  <p>What one would like, would be something like a hypothetical:</p>
  <pre><code>repeat(3, Math.random) // Outputs: [0.214259553965, 0.002260502324, 0.452618881464]
  </code></pre>
  <p>What's the closest we can do using vanilla JavaScript?</p>
  <p>I'm aware of libraries like Underscore, but I'm trying to avoid libraries here.</p>
  <p>I looked at the answers to <a href="https://stackoverflow.com/questions/1877475/repeat-character-n-times">Repeat a string a number of times</a>, but it is not applicable in general. E.g.:</p>
  <pre><code>Array(3).map(Math.random) // Outputs: [undefined, undefined, undefined]
  Array(4).join(Math.random()) // Outputs a concatenation of a repeated number
  Array(3).fill(Math.random()) // Fills with the same number
  </code></pre>
  <p>Several other answers propose modifying a built-in class; a practice that I consider completely unacceptable.</p>