1 | export default function repeating(count, repeatString = ' ') {
|
2 | if (typeof repeatString !== 'string') {
|
3 | throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof repeatString}\``);
|
4 | }
|
5 |
|
6 | if (count < 0 || !Number.isFinite(count)) {
|
7 | throw new TypeError(`Expected \`count\` to be a positive finite number, got \`${count}\``);
|
8 | }
|
9 |
|
10 | let returnValue = '';
|
11 |
|
12 | do {
|
13 | if (count & 1) {
|
14 | returnValue += repeatString;
|
15 | }
|
16 |
|
17 | repeatString += repeatString;
|
18 | } while ((count >>= 1));
|
19 |
|
20 | return returnValue;
|
21 | }
|