repeat-element NPM version

Create an array by repeating the given value n times.

Install

Install with npm

  1. npm i repeat-element --save

Usage

  1. var repeat = require('repeat-element');
  2. repeat('a', 5);
  3. //=> ['a', 'a', 'a', 'a', 'a']
  4. repeat('a', 1);
  5. //=> ['a']
  6. repeat('a', 0);
  7. //=> []
  8. repeat(null, 5)
  9. //» [ null, null, null, null, null ]
  10. repeat({some: 'object'}, 5)
  11. //» [ { some: 'object' },
  12. // { some: 'object' },
  13. // { some: 'object' },
  14. // { some: 'object' },
  15. // { some: 'object' } ]
  16. repeat(5, 5)
  17. //» [ 5, 5, 5, 5, 5 ]

Related projects

repeat-string: Repeat the given string n times. Fastest implementation for repeating a string.

Running tests

Install dev dependencies:

  1. npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 06, 2015.