arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

repeat-string

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

hashtag
Install

Install with npmarrow-up-right:

hashtag
Usage

hashtag

Repeat the given string the specified number of times.

Example:

Example

Params

  • string {String}: The string to repeat

  • number {Number}: The number of times to repeat the string

  • returns

hashtag
Benchmarks

Repeat string is significantly faster than the native method (which is itself faster than ):

Run the benchmarks

Install dev dependencies:

hashtag
About

hashtag
Related projects

: Create an array by repeating the given value n times. |

hashtag
Contributing

Pull requests and stars are always welcome. For bugs and feature requests, .

hashtag
Contributors

hashtag
Building docs

(This document was generated by (a generator), please don't edit the readme directly. Any changes to the readme must be made in .)

To generate the readme and API documentation with :

hashtag
Running tests

Install dev dependencies:

hashtag
Author

Jon Schlinkert

hashtag
License

Copyright Β© 2016, . Released under the .

This file was generated by , v0.2.0, on October 23, 2016.

$ npm install --save repeat-string
{String}
: Repeated string

Commits

Contributor

51

2

2

1

1

repeatarrow-up-right
repeatingarrow-up-right
repeat-elementarrow-up-right
homepagearrow-up-right
please create an issuearrow-up-right
verb-generate-readmearrow-up-right
verbarrow-up-right
.verb.mdarrow-up-right
verbarrow-up-right
github/jonschlinkertarrow-up-right
twitter/jonschlinkertarrow-up-right
Jon Schlinkertarrow-up-right
MIT licensearrow-up-right
verb-generate-readmearrow-up-right
var repeat = require('repeat-string');
repeat('A', 5);
//=> AAAAA
# 2x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (26,953,977 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                  (9,855,695 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         (19,453,895 ops/sec)

# 3x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (19,445,252 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                (8,661,565 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ       (16,020,598 ops/sec)

# 10x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (23,792,521 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                  (8,571,332 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ            (14,582,955 ops/sec)

# 50x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (23,640,179 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                      (5,505,509 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                 (10,085,557 ops/sec)

# 250x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (23,489,618 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆ                       (3,962,937 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                   (7,724,892 ops/sec)

# 2000x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (20,315,172 ops/sec)
repeating      β–ˆβ–ˆβ–ˆβ–ˆ                       (3,297,079 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                    (6,203,331 ops/sec)

# 20000x
repeat-string  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  (23,382,915 ops/sec)
repeating      β–ˆβ–ˆβ–ˆ                        (2,980,058 ops/sec)
native         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                      (5,578,808 ops/sec)
npm i -d && node benchmark
$ npm install -g verb verb-generate-readme && verb
$ npm install -d && npm test
jonschlinkertarrow-up-right
LinusUarrow-up-right
tbusserarrow-up-right
doowbarrow-up-right
wooormarrow-up-right