index.js 397 B

12345678910111213141516171819202122
  1. /*!
  2. * repeat-element <https://github.com/jonschlinkert/repeat-element>
  3. *
  4. * Copyright (c) 2015-present, Jon Schlinkert.
  5. * Licensed under the MIT license.
  6. */
  7. 'use strict';
  8. module.exports = function repeat(ele, num) {
  9. if (Array.prototype.fill) {
  10. return new Array(num).fill(ele);
  11. }
  12. var arr = new Array(num);
  13. for (var i = 0; i < num; i++) {
  14. arr[i] = ele;
  15. }
  16. return arr;
  17. };