← Back to challenges

Repeat a Char

JavaScriptHardalgorithms

Instructions

In this challenge you should repeat a specific given char x times. Create a function that takes a string and a number as arguments and return a string.

Examples

repeat("-", 3) ➞ "---"

repeat("A", 0) ➞ ""

repeat("c", -1) ➞ ""

Notes

  • Tests can repeat a char 268435440 times, no more.
  • Repeat should be fast maximum execution time : 5 ms.
  • Total maximum execution time : 3800 ms.
  • Native repeat is forbidden.
  • Using of an existing repeat polyfill too (that's not the challenge objective).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.