Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
String repeat
easy10 min
Build a string by repeating its contents a requested number of times, using the numeric-count rules of String repeat.
Requirements
Implement stringRepeat(text, count = 0) as a standalone function. Do not modify String.prototype or call native repeat.
Assume text is a string and count is numeric. Truncate fractional counts towards zero; omitted, undefined, or NaN counts mean 0.
Throw RangeError when the normalized count is negative or infinite. A negative fraction between -1 and 0 normalizes to 0 and returns an empty string.
Return an empty string for a valid zero count or empty text. Preserve all characters and code units without adding separators. Validate invalid counts even when text is empty.
Assume valid output contains at most 10,000 UTF-16 code units. General argument coercion and engine-specific maximum string lengths are outside scope.