String.prototype.repeat returns a new string made of count copies of the original, joined end to end with nothing between them. It's how you build a divider line ('='.repeat(40)), indentation, or any fixed-width filler.
Implement stringRepeat(str, count). Concatenate str with itself count times and return the result. A count of 0 gives ''. A negative or infinite count is invalid — throw a RangeError.
function stringRepeat(str, count) {
// returns str concatenated `count` times; throws RangeError if count
// is negative or Infinity.
}
stringRepeat('ab', 3); // 'ababab'
stringRepeat('=', 5); // '====='
stringRepeat('x', 0); // ''
stringRepeat('ab', -1); // throws RangeError
stringRepeat('ab', Infinity); // throws RangeError
stringRepeat('-', 3) is '---', not '- - -'.count of 0 — returns the empty string, not the original.count — truncated toward zero: 2.9 means 2 repeats.Infinity — throw a RangeError. These are the only inputs that throw.NaN count — treated as 0, so the result is '' (no throw).