UNPKG

@extra-array/repeat

Version:
49 lines (35 loc) 1.4 kB
Repeats an array given times. [:package:](https://www.npmjs.com/package/@extra-array/repeat) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/repeat) [:vhs:](https://asciinema.org/a/332116) [:moon:](https://www.npmjs.com/package/@extra-array/repeat.min) [:scroll:](https://unpkg.com/@extra-array/repeat/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [repeat], [cycle], [rotate], [reverse]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.repeat(x, [n]); // x: an array // n: times (1) ``` ```javascript const array = require("extra-array"); var x = [1, 2]; array.repeat(x, 2); // [ 1, 2, 1, 2 ] array.repeat(x, 3); // [ 1, 2, 1, 2, 1, 2 ] ``` <br> <br> ## References - [String.prototype.repeat: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) - [Collections.nCopies: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#nCopies(int,%20T)) [repeat]: https://github.com/nodef/extra-array/wiki/repeat [cycle]: https://github.com/nodef/extra-array/wiki/cycle [rotate]: https://github.com/nodef/extra-array/wiki/rotate [reverse]: https://github.com/nodef/extra-array/wiki/reverse