"-".repeat(20) draws a divider, " ".repeat(depth) indents a tree, and "*".repeat(stars) draws a rating. Rebuilding repeat yourself is a short exercise in how a built-in method really works: how it converts its argument, when it throws, what this is inside a method on String.prototype, and how to build a long string without a long loop.
Write String.prototype.myRepeat(count) in repeat.js. The starter already adds it to String.prototype with Object.defineProperty; fill in the function.
Returns the string repeated count times: "ab".myRepeat(3) is "ababab". A count of 1 gives the string, 0 gives "", and an empty string stays empty for any finite count.
Works for large counts (a million copies) within the time limit, and for an empty string with a count of a billion.
Converts count to a number ("3", true, an object with valueOf) and drops its fraction toward zero: 2.9 means 2. A BigInt or a Symbol count (or an object whose valueOf returns one) throws a TypeError, as the built-in does.
A missing count, NaN, or a string that is not a number counts as 0. A count between -1 and 0 (such as -0.5) becomes 0, not an error.
Throws a RangeError for a negative count (after dropping the fraction) and for Infinity, even on an empty string.
Converts this to a string, so it works when called on a number, a BigInt, a boolean or a String object, and always returns a primitive string. Called on a Symbol, it throws a TypeError, as the built-in does.
Throws a TypeError when called on null or undefined, before it looks at the count.
Uses none of String.prototype.repeat, padStart, padEnd or Array.prototype.join, and adds no enumerable property to strings.